summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2012-04-24 15:03:47 -0700
committerJeff Sharkey <jsharkey@android.com>2012-04-24 15:05:33 -0700
commit15ea8d69f74735e2013cc11bc4899e0edc945b8a (patch)
tree79f4f7939966e9ce9d06edb0a981775bacdb1d5a /src
parent2f5fe598e53fc7bb3e8d6e1848ab62953866fb11 (diff)
downloadandroid_packages_providers_DownloadProvider-15ea8d69f74735e2013cc11bc4899e0edc945b8a.tar.gz
android_packages_providers_DownloadProvider-15ea8d69f74735e2013cc11bc4899e0edc945b8a.tar.bz2
android_packages_providers_DownloadProvider-15ea8d69f74735e2013cc11bc4899e0edc945b8a.zip
Only delete spurious files belonging to us.
When multiple users are active, this can accidentally delete files belonging to other users. Checking owner also helps us avoid deleting recover and lost+found. Bug: 6362988 Change-Id: Ifc165acc9a9b3ab253a4b6257f370836b98b3a74
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/downloads/Constants.java3
-rw-r--r--src/com/android/providers/downloads/StorageManager.java29
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();
}
}