From 60a3804c5aa39b1975b50ba8de028c6a2a70f038 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 24 Dec 2015 09:57:30 +1100 Subject: [PATCH] Make sure to insert, rather than update apks when updating repo. Fixes #517. The problem was that again, only the `vercode`s of apks were being compared to see if they were the same, rather than `vercode` and `id`. The result is that some new apks will incorrectly be asked to execute an `UPDATE` query rather than an `INSERT`. As such, they don't end up in our database at all because the `UPDATE` will not run against any row at all. --- F-Droid/src/org/fdroid/fdroid/data/RepoPersister.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/data/RepoPersister.java b/F-Droid/src/org/fdroid/fdroid/data/RepoPersister.java index 6d223df2b..bc2e914db 100644 --- a/F-Droid/src/org/fdroid/fdroid/data/RepoPersister.java +++ b/F-Droid/src/org/fdroid/fdroid/data/RepoPersister.java @@ -160,12 +160,16 @@ public class RepoPersister { * will queue up an update or an insert {@link ContentProviderOperation} for each package. */ private ArrayList insertOrUpdateApks(List packages) { - List existingApks = ApkProvider.Helper.knownApks(context, packages, new String[]{ApkProvider.DataColumns.VERSION_CODE}); + String[] projection = new String[]{ + ApkProvider.DataColumns.APK_ID, + ApkProvider.DataColumns.VERSION_CODE, + }; + List existingApks = ApkProvider.Helper.knownApks(context, packages, projection); ArrayList operations = new ArrayList<>(packages.size()); for (Apk apk : packages) { boolean exists = false; for (Apk existing : existingApks) { - if (existing.vercode == apk.vercode) { + if (existing.id.equals(apk.id) && existing.vercode == apk.vercode) { exists = true; break; }