DO NOT MERGE. Use resolved path for both checking and opening. am: 8a2e551874
[android/platform/packages/providers/DownloadProvider.git] / src / com / android / providers / downloads / Helpers.java
index 61a49a2..5f2c67f 100644 (file)
@@ -141,7 +141,15 @@ public class Helpers {
             // Claim this filename inside lock to prevent other threads from
             // clobbering us. We're not paranoid enough to use O_EXCL.
             try {
-                new File(path).createNewFile();
+                File file = new File(path);
+                File parent = file.getParentFile();
+
+                // Make sure the parent directories exists before generates new file
+                if (parent != null && !parent.exists()) {
+                    parent.mkdirs();
+                }
+
+                file.createNewFile();
             } catch (IOException e) {
                 throw new StopRequestException(Downloads.Impl.STATUS_FILE_ERROR,
                         "Failed to create target file " + path, e);