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.
This commit is contained in:
Peter Serwylo 2016-07-20 06:56:06 +10:00
parent 698c517508
commit 52195bb3e9

View File

@ -334,7 +334,7 @@ public class RepoProvider extends FDroidProvider {
return 0; return 0;
case CODE_SINGLE: case CODE_SINGLE:
selection.add(Cols._ID + " = ?", new String[] {uri.getLastPathSegment()}); selection = selection.add(Cols._ID + " = ?", new String[] {uri.getLastPathSegment()});
break; break;
default: default:
@ -343,7 +343,7 @@ public class RepoProvider extends FDroidProvider {
} }
int rowsAffected = db().delete(getTableName(), selection.getSelection(), selection.getArgs()); 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); getContext().getContentResolver().notifyChange(uri, null);
return rowsAffected; return rowsAffected;
} }