diff options
-rw-r--r-- | src/com/android/providers/downloads/Constants.java | 3 | ||||
-rw-r--r-- | src/com/android/providers/downloads/StorageManager.java | 29 |
2 files changed, 20 insertions, 12 deletions
diff --git a/src/com/android/providers/downloads/Constants.java b/src/com/android/providers/downloads/Constants.java index 27e2179e..8481435f 100644 --- a/src/com/android/providers/downloads/Constants.java +++ b/src/com/android/providers/downloads/Constants.java @@ -85,9 +85,6 @@ public class Constants { public static final String DEFAULT_DL_SUBDIR = "/" + Environment.DIRECTORY_DOWNLOADS; /** A magic filename that is allowed to exist within the system cache */ - public static final String KNOWN_SPURIOUS_FILENAME = "lost+found"; - - /** A magic filename that is allowed to exist within the system cache */ public static final String RECOVERY_DIRECTORY = "recovery"; /** The default user agent used for downloads */ diff --git a/src/com/android/providers/downloads/StorageManager.java b/src/com/android/providers/downloads/StorageManager.java index 19132b51..4b51921f 100644 --- a/src/com/android/providers/downloads/StorageManager.java +++ b/src/com/android/providers/downloads/StorageManager.java @@ -16,6 +16,9 @@ package com.android.providers.downloads; +import static com.android.providers.downloads.Constants.LOGV; +import static com.android.providers.downloads.Constants.TAG; + import android.content.ContentUris; import android.content.Context; import android.content.res.Resources; @@ -36,6 +39,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import libcore.io.ErrnoException; +import libcore.io.Libcore; +import libcore.io.StructStat; + /** * Manages the storage space consumed by Downloads Data dir. When space falls below * a threshold limit (set in resource xml files), starts cleanup of the Downloads data dir @@ -388,7 +395,7 @@ class StorageManager { while (cursor.moveToNext()) { String filename = cursor.getString(0); if (!TextUtils.isEmpty(filename)) { - if (true || Constants.LOGV) { + if (LOGV) { Log.i(Constants.TAG, "in removeSpuriousFiles, preserving file " + filename); } @@ -401,16 +408,20 @@ class StorageManager { cursor.close(); } } - // delete the files not found in the database + + // delete files owned by us, but that don't appear in our database + final int myUid = android.os.Process.myUid(); for (File file : files) { - if (file.getName().equals(Constants.KNOWN_SPURIOUS_FILENAME) || - file.getName().equalsIgnoreCase(Constants.RECOVERY_DIRECTORY)) { - continue; - } - if (true || Constants.LOGV) { - Slog.d(Constants.TAG, "deleting spurious file " + file.getAbsolutePath()); + final String path = file.getAbsolutePath(); + try { + final StructStat stat = Libcore.os.stat(path); + if (stat.st_uid == myUid) { + Slog.d(TAG, "deleting spurious file " + path); + file.delete(); + } + } catch (ErrnoException e) { + Log.w(TAG, "stat(" + path + ") result: " + e); } - file.delete(); } } |