Merge branch 'fix-517--repo-update-sadness' into 'master'

Correctly purge removed apks.

There were two bugs in this code that have been fixed. Both were
introduced while moving to a lower memory consumption version of
the repo updater for #324.

They were found while investigating #517, although I'm not confident
that they are to do with the specific problem in that issue. It is
possible, because it is part of the code to do with purging apks
from the database, but I'd like to do further investigations into
the code before declaring that this is actually related to that issue.

In the mean time, this includes important fixes, and should probably
go out in an alpha once merged.

The first is that for each app which is updated by a particular repo,
it was not correctly asking the question: "Which apks belonging to
this apk, and provided by this repo, are no longer provided by this
repo?". It was accidentally only comparing the version number of
existing apks in the DB and new apks from the index. This ensures
that the apks being checked to see if they need to be removed or
not are those with the same package name AND the same version code
(provided by the same repo).

The second bug is that when it was persisting a set of apps + apks
to the database, it would ask for existing apks already in the
database for these apps. In this case, there was a bug where of
the 50 apps being persisted, it would only retrieve the first of
these 50 apps from the database to decide if it needed to be
cleaned up or not. Now, it correctly retrieves data from the DB
belonging to all 50 apps.

See merge request !181
This commit is contained in:
Peter Serwylo 2015-12-22 20:34:44 +00:00
commit b7eb30a69b
2 changed files with 3 additions and 10 deletions

View File

@ -340,7 +340,7 @@ public class ApkProvider extends FDroidProvider {
if (i != 0) {
builder.append(',');
}
builder.append(apks.get(0).id);
builder.append(apks.get(i).id);
}
return builder.toString();
}

View File

@ -243,27 +243,20 @@ public class RepoPersister {
*/
@Nullable
private ContentProviderOperation deleteOrphanedApks(List<App> apps, Map<String, List<Apk>> packages) {
String[] projection = new String[]{ApkProvider.DataColumns.APK_ID, ApkProvider.DataColumns.VERSION_CODE};
List<Apk> existing = ApkProvider.Helper.find(context, repo, apps, projection);
List<Apk> toDelete = new ArrayList<>();
for (Apk existingApk : existing) {
boolean shouldStay = false;
for (Map.Entry<String, List<Apk>> entry : packages.entrySet()) {
for (Apk newApk : entry.getValue()) {
if (packages.containsKey(existingApk.id)) {
for (Apk newApk : packages.get(existingApk.id)) {
if (newApk.vercode == existingApk.vercode) {
shouldStay = true;
break;
}
}
if (shouldStay) {
break;
}
}
if (!shouldStay) {