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

Make sure to insert, rather than update apks when updating repo.

(Actually) fixes #517. I had a hunch the other bug (though problematic) wasn't actually the fix for #517. I am confident that this one _is_ the fix, although I am still struggling to reproduce specific circumstances reported by others. I tracked this down when I did an update this morning and noticed a new app without any versions - so in a way I kind of reproduced it, but I can't reproduce it at will.

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.

See merge request !182
This commit is contained in:
Daniel Martí 2015-12-24 16:16:12 +00:00
commit 62885db7c4

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;
}