From e3960ea97d5ddee80e5237796d577892e42a28cb Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Tue, 16 Jun 2015 17:06:37 -0700 Subject: Actually delete files when rows are deleted. Otherwise they're orphaned until the next idle maintenance pass. Bug: 21786983 Change-Id: I6eb2240d657366b65482bd3a0d5683e5d34a541a --- .../android/providers/downloads/DownloadProvider.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java index 4b23024f..b19da709 100644 --- a/src/com/android/providers/downloads/DownloadProvider.java +++ b/src/com/android/providers/downloads/DownloadProvider.java @@ -1142,9 +1142,7 @@ public final class DownloadProvider extends ContentProvider { * Deletes a row in the database */ @Override - public int delete(final Uri uri, final String where, - final String[] whereArgs) { - + public int delete(final Uri uri, final String where, final String[] whereArgs) { if (shouldRestrictVisibility()) { Helpers.validateSelection(where, sAppReadableColumnsSet); } @@ -1161,12 +1159,21 @@ public final class DownloadProvider extends ContentProvider { deleteRequestHeaders(db, selection.getSelection(), selection.getParameters()); final Cursor cursor = db.query(DB_TABLE, new String[] { - Downloads.Impl._ID }, selection.getSelection(), selection.getParameters(), - null, null, null); + Downloads.Impl._ID, Downloads.Impl._DATA + }, selection.getSelection(), selection.getParameters(), null, null, null); try { while (cursor.moveToNext()) { final long id = cursor.getLong(0); DownloadStorageProvider.onDownloadProviderDelete(getContext(), id); + + final String path = cursor.getString(1); + if (!TextUtils.isEmpty(path)) { + final File file = new File(path); + if (Helpers.isFilenameValid(getContext(), file)) { + Log.v(Constants.TAG, "Deleting " + file + " via provider delete"); + file.delete(); + } + } } } finally { IoUtils.closeQuietly(cursor); -- cgit v1.2.3