bug:3332449 downloadmanager deleting downloaded files sometimes
Vasu Nori [Thu, 13 Jan 2011 00:26:42 +0000 (16:26 -0800)]
removeSpuriousFiles() method in StorageManager.java is removing
files because of it incorrectly thought a given file has NO entry
in downloads db.

more details:
  List<File> files;
  String filename;
  files.remove(filename)
remove should be new File(filename)

most probably this fix also addresses bug:3324673

Change-Id: I22c58398fe874fa81939b575c782b6700a2cac4e

src/com/android/providers/downloads/StorageManager.java

index e9638b8..7265834 100644 (file)
@@ -26,6 +26,7 @@ import android.net.Uri;
 import android.os.Environment;
 import android.os.StatFs;
 import android.provider.Downloads;
+import android.text.TextUtils;
 import android.util.Log;
 
 import com.android.internal.R;
@@ -373,14 +374,20 @@ class StorageManager {
         if (files.size() == 0) {
             return;
         }
-
         Cursor cursor = mContext.getContentResolver().query(
                 Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI,
                 new String[] { Downloads.Impl._DATA }, null, null, null);
         try {
             if (cursor != null) {
                 while (cursor.moveToNext()) {
-                    files.remove(cursor.getString(0));
+                    String filename = cursor.getString(0);
+                    if (!TextUtils.isEmpty(filename)) {
+                        if (Constants.LOGV) {
+                            Log.i(Constants.TAG, "in removeSpuriousFiles, preserving file " +
+                                    filename);
+                        }
+                        files.remove(new File(filename));
+                    }
                 }
             }
         } finally {