Fixed update code to work with signed repos that haven't changed.
This commit is contained in:
parent
2b1c335ea9
commit
535d343faf
@ -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
|
||||
// also done based on compatibility and anti-features according to
|
||||
// the user's current preferences.
|
||||
|
@ -207,7 +207,6 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
|
||||
sendStatus(STATUS_INFO,
|
||||
getString(R.string.status_checking_compatibility));
|
||||
apps = ((FDroidApp) getApplication()).getApps();
|
||||
|
||||
DB db = DB.getDB();
|
||||
try {
|
||||
@ -226,7 +225,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
}
|
||||
if (keepapp) {
|
||||
DB.App app_k = null;
|
||||
for (DB.App app2 : updatingApps) {
|
||||
for (DB.App app2 : apps) {
|
||||
if (app2.id.equals(app.id)) {
|
||||
app_k = app2;
|
||||
break;
|
||||
|
@ -135,4 +135,8 @@ public class Downloader {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasChanged() {
|
||||
return this.statusCode == 200;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -62,11 +62,14 @@ abstract public class RepoUpdater {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the index file if it is different than last time,
|
||||
* otherwise returns null to indicate that the file has not changed.
|
||||
* All error states will come via an UpdateException.
|
||||
* For example, you may want to unzip a jar file to get the index inside,
|
||||
* or if the file is not compressed, you can just return a reference to
|
||||
* 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();
|
||||
|
||||
@ -86,14 +89,13 @@ abstract public class RepoUpdater {
|
||||
|
||||
int status = downloader.download();
|
||||
|
||||
repo.lastetag = downloader.getETag();
|
||||
if (status == 304) {
|
||||
// The index is unchanged since we last read it. We just mark
|
||||
// everything that came from this repo as being updated.
|
||||
Log.d("FDroid", "Repo index for " + repo.address
|
||||
+ " is up to date (by etag)");
|
||||
} else if (status == 200) {
|
||||
hasChanged = true;
|
||||
// Nothing needed to be done here...
|
||||
} else {
|
||||
// Is there any code other than 200 which still returns
|
||||
// content? Just in case, lets try to clean up.
|
||||
@ -152,28 +154,38 @@ abstract public class RepoUpdater {
|
||||
|
||||
public void update() throws UpdateException {
|
||||
|
||||
File downloadedFile = null;
|
||||
File indexFile = null;
|
||||
try {
|
||||
indexFile = getIndexFile();
|
||||
|
||||
// Process the index...
|
||||
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
|
||||
XMLReader reader = parser.getXMLReader();
|
||||
RepoXMLHandler handler = new RepoXMLHandler(repo, apps, progressListener);
|
||||
Downloader downloader = downloadIndex();
|
||||
hasChanged = downloader.hasChanged();
|
||||
|
||||
if (isInteractive()) {
|
||||
// Only bother spending the time to count the expected apps
|
||||
// if we can show that to the user...
|
||||
handler.setTotalAppCount(estimateAppCount(indexFile));
|
||||
if (hasChanged) {
|
||||
|
||||
downloadedFile = downloader.getFile();
|
||||
repo.lastetag = downloader.getETag();
|
||||
|
||||
indexFile = getIndexFromFile(downloadedFile);
|
||||
|
||||
// Process the index...
|
||||
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
|
||||
XMLReader reader = parser.getXMLReader();
|
||||
RepoXMLHandler handler = new RepoXMLHandler(repo, apps, progressListener);
|
||||
|
||||
if (isInteractive()) {
|
||||
// Only bother spending the time to count the expected apps
|
||||
// if we can show that to the user...
|
||||
handler.setTotalAppCount(estimateAppCount(indexFile));
|
||||
}
|
||||
|
||||
reader.setContentHandler(handler);
|
||||
InputSource is = new InputSource(
|
||||
new BufferedReader(new FileReader(indexFile)));
|
||||
|
||||
reader.parse(is);
|
||||
updateRepo(handler.getPubKey(), handler.getMaxAge());
|
||||
}
|
||||
|
||||
reader.setContentHandler(handler);
|
||||
InputSource is = new InputSource(
|
||||
new BufferedReader(new FileReader(indexFile)));
|
||||
|
||||
reader.parse(is);
|
||||
updateRepo(handler.getPubKey(), handler.getMaxAge());
|
||||
|
||||
} catch (SAXException e) {
|
||||
throw new UpdateException(
|
||||
repo, "Error parsing index for repo " + repo.address, e);
|
||||
@ -187,9 +199,14 @@ abstract public class RepoUpdater {
|
||||
throw new UpdateException(
|
||||
repo, "Error parsing index for repo " + repo.address, e);
|
||||
} finally {
|
||||
if (downloadedFile != null &&
|
||||
downloadedFile != indexFile && downloadedFile.exists()) {
|
||||
downloadedFile.delete();
|
||||
}
|
||||
if (indexFile != null && indexFile.exists()) {
|
||||
indexFile.delete();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,23 +91,19 @@ public class SignedRepoUpdater extends RepoUpdater {
|
||||
* check the signature, and extract the index file
|
||||
*/
|
||||
@Override
|
||||
protected File getIndexFile() throws UpdateException {
|
||||
protected File getIndexFromFile(File downloadedFile) throws
|
||||
UpdateException {
|
||||
Date updateTime = new Date(System.currentTimeMillis());
|
||||
Log.d("FDroid", "Getting signed index from " + repo.address + " at " +
|
||||
Utils.LOG_DATE_FORMAT.format(updateTime));
|
||||
|
||||
Downloader downloader = downloadIndex();
|
||||
File indexJar = downloader.getFile();
|
||||
File indexJar = downloadedFile;
|
||||
File indexXml = null;
|
||||
|
||||
// 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:
|
||||
if (indexJar != null && indexJar.exists()) {
|
||||
try {
|
||||
indexXml = extractIndexFromJar(indexJar);
|
||||
} finally {
|
||||
indexJar.delete();
|
||||
}
|
||||
indexXml = extractIndexFromJar(indexJar);
|
||||
}
|
||||
return indexXml;
|
||||
}
|
||||
|
@ -14,10 +14,9 @@ public class UnsignedRepoUpdater extends RepoUpdater {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File getIndexFile() throws UpdateException {
|
||||
protected File getIndexFromFile(File file) throws UpdateException {
|
||||
Log.d("FDroid", "Getting unsigned index from " + getIndexAddress());
|
||||
Downloader downloader = downloadIndex();
|
||||
return downloader.getFile();
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user