Fixed update code to work with signed repos that haven't changed.

This commit is contained in:
Peter Serwylo 2014-01-03 06:15:45 +11:00
parent 2b1c335ea9
commit 535d343faf
6 changed files with 51 additions and 47 deletions

View File

@ -796,17 +796,6 @@ public class DB {
} }
} }
// Repopulate the details for the given app.
// If 'apkrepo' is non-zero, only apks from that repo are
// populated.
public void repopulateDetails(App app, int apkRepo) {
populateAppDetails(app);
for (Apk apk : app.apks) {
populateApkDetails(apk, apkRepo);
}
}
// Return a list of apps matching the given criteria. Filtering is // Return a list of apps matching the given criteria. Filtering is
// also done based on compatibility and anti-features according to // also done based on compatibility and anti-features according to
// the user's current preferences. // the user's current preferences.

View File

@ -207,7 +207,6 @@ public class UpdateService extends IntentService implements ProgressListener {
sendStatus(STATUS_INFO, sendStatus(STATUS_INFO,
getString(R.string.status_checking_compatibility)); getString(R.string.status_checking_compatibility));
apps = ((FDroidApp) getApplication()).getApps();
DB db = DB.getDB(); DB db = DB.getDB();
try { try {
@ -226,7 +225,7 @@ public class UpdateService extends IntentService implements ProgressListener {
} }
if (keepapp) { if (keepapp) {
DB.App app_k = null; DB.App app_k = null;
for (DB.App app2 : updatingApps) { for (DB.App app2 : apps) {
if (app2.id.equals(app.id)) { if (app2.id.equals(app.id)) {
app_k = app2; app_k = app2;
break; break;

View File

@ -135,4 +135,8 @@ public class Downloader {
} }
} }
public boolean hasChanged() {
return this.statusCode == 200;
}
} }

View File

@ -62,11 +62,14 @@ abstract public class RepoUpdater {
} }
/** /**
* Return the index file if it is different than last time, * For example, you may want to unzip a jar file to get the index inside,
* otherwise returns null to indicate that the file has not changed. * or if the file is not compressed, you can just return a reference to
* All error states will come via an UpdateException. * the downloaded file.
*
* @throws UpdateException All error states will come from here.
*/ */
protected abstract File getIndexFile() throws UpdateException; protected abstract File getIndexFromFile(File downloadedFile) throws
UpdateException;
protected abstract String getIndexAddress(); protected abstract String getIndexAddress();
@ -86,14 +89,13 @@ abstract public class RepoUpdater {
int status = downloader.download(); int status = downloader.download();
repo.lastetag = downloader.getETag();
if (status == 304) { if (status == 304) {
// The index is unchanged since we last read it. We just mark // The index is unchanged since we last read it. We just mark
// everything that came from this repo as being updated. // everything that came from this repo as being updated.
Log.d("FDroid", "Repo index for " + repo.address Log.d("FDroid", "Repo index for " + repo.address
+ " is up to date (by etag)"); + " is up to date (by etag)");
} else if (status == 200) { } else if (status == 200) {
hasChanged = true; // Nothing needed to be done here...
} else { } else {
// Is there any code other than 200 which still returns // Is there any code other than 200 which still returns
// content? Just in case, lets try to clean up. // content? Just in case, lets try to clean up.
@ -152,9 +154,19 @@ abstract public class RepoUpdater {
public void update() throws UpdateException { public void update() throws UpdateException {
File downloadedFile = null;
File indexFile = null; File indexFile = null;
try { try {
indexFile = getIndexFile();
Downloader downloader = downloadIndex();
hasChanged = downloader.hasChanged();
if (hasChanged) {
downloadedFile = downloader.getFile();
repo.lastetag = downloader.getETag();
indexFile = getIndexFromFile(downloadedFile);
// Process the index... // Process the index...
SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
@ -173,7 +185,7 @@ abstract public class RepoUpdater {
reader.parse(is); reader.parse(is);
updateRepo(handler.getPubKey(), handler.getMaxAge()); updateRepo(handler.getPubKey(), handler.getMaxAge());
}
} catch (SAXException e) { } catch (SAXException e) {
throw new UpdateException( throw new UpdateException(
repo, "Error parsing index for repo " + repo.address, e); repo, "Error parsing index for repo " + repo.address, e);
@ -187,9 +199,14 @@ abstract public class RepoUpdater {
throw new UpdateException( throw new UpdateException(
repo, "Error parsing index for repo " + repo.address, e); repo, "Error parsing index for repo " + repo.address, e);
} finally { } finally {
if (downloadedFile != null &&
downloadedFile != indexFile && downloadedFile.exists()) {
downloadedFile.delete();
}
if (indexFile != null && indexFile.exists()) { if (indexFile != null && indexFile.exists()) {
indexFile.delete(); indexFile.delete();
} }
} }
} }

View File

@ -91,23 +91,19 @@ public class SignedRepoUpdater extends RepoUpdater {
* check the signature, and extract the index file * check the signature, and extract the index file
*/ */
@Override @Override
protected File getIndexFile() throws UpdateException { protected File getIndexFromFile(File downloadedFile) throws
UpdateException {
Date updateTime = new Date(System.currentTimeMillis()); Date updateTime = new Date(System.currentTimeMillis());
Log.d("FDroid", "Getting signed index from " + repo.address + " at " + Log.d("FDroid", "Getting signed index from " + repo.address + " at " +
Utils.LOG_DATE_FORMAT.format(updateTime)); Utils.LOG_DATE_FORMAT.format(updateTime));
Downloader downloader = downloadIndex(); File indexJar = downloadedFile;
File indexJar = downloader.getFile();
File indexXml = null; File indexXml = null;
// Don't worry about checking the status code for 200. If it was a // Don't worry about checking the status code for 200. If it was a
// successful download, then we will have a file ready to use: // successful download, then we will have a file ready to use:
if (indexJar != null && indexJar.exists()) { if (indexJar != null && indexJar.exists()) {
try {
indexXml = extractIndexFromJar(indexJar); indexXml = extractIndexFromJar(indexJar);
} finally {
indexJar.delete();
}
} }
return indexXml; return indexXml;
} }

View File

@ -14,10 +14,9 @@ public class UnsignedRepoUpdater extends RepoUpdater {
} }
@Override @Override
protected File getIndexFile() throws UpdateException { protected File getIndexFromFile(File file) throws UpdateException {
Log.d("FDroid", "Getting unsigned index from " + getIndexAddress()); Log.d("FDroid", "Getting unsigned index from " + getIndexAddress());
Downloader downloader = downloadIndex(); return file;
return downloader.getFile();
} }
@Override @Override