From 52195bb3e9468ef8d3252af693f49fd941c31922 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Wed, 20 Jul 2016 06:56:06 +1000 Subject: [PATCH] Correctly delete single repo, not all repos. In a recent commit, I cleaned up the code which deletes repo. At that point, instead of maybe concatenating strings together, sometimes with an `AND` statement, it was changed to use the slightly better `QuerySelection`. This class is preferable because it doesn't need the developer to know whether there was any previous constraints, and thus it knows whether to prepend an `AND`. The problem arose because `QuerySelection` is effectively an immutable class. Calling `add()` on it returns a new copy with a different set of constraints. The code which deleted the repo did not use this copy, and thus the resulting query had zero constraints. The fix is to use the return value of `add()` correctly. It would've been easier to identify this bug if we had a lint check for "unused return values", though it is likely that that would get annoying very quickly. Fixes #717. --- app/src/main/java/org/fdroid/fdroid/data/RepoProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/data/RepoProvider.java b/app/src/main/java/org/fdroid/fdroid/data/RepoProvider.java index c9e8b860a..27f8b0329 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/RepoProvider.java +++ b/app/src/main/java/org/fdroid/fdroid/data/RepoProvider.java @@ -334,7 +334,7 @@ public class RepoProvider extends FDroidProvider { return 0; case CODE_SINGLE: - selection.add(Cols._ID + " = ?", new String[] {uri.getLastPathSegment()}); + selection = selection.add(Cols._ID + " = ?", new String[] {uri.getLastPathSegment()}); break; default: @@ -343,7 +343,7 @@ public class RepoProvider extends FDroidProvider { } int rowsAffected = db().delete(getTableName(), selection.getSelection(), selection.getArgs()); - Utils.debugLog(TAG, "Deleted repos. Notifying provider change: '" + uri + "'."); + Utils.debugLog(TAG, "Deleted repo. Notifying provider change: '" + uri + "'."); getContext().getContentResolver().notifyChange(uri, null); return rowsAffected; }