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.
This commit is contained in:
Peter Serwylo 2015-12-24 09:57:30 +11:00
parent b7eb30a69b
commit 60a3804c5a

View File

@ -160,12 +160,16 @@ public class RepoPersister {
* will queue up an update or an insert {@link ContentProviderOperation} for each package.
*/
private ArrayList<ContentProviderOperation> insertOrUpdateApks(List<Apk> packages) {
List<Apk> 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<Apk> existingApks = ApkProvider.Helper.knownApks(context, packages, projection);
ArrayList<ContentProviderOperation> 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;
}