summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoger Chen <cxr514033970@gmail.com>2014-01-03 06:37:26 (GMT)
committerelektroschmock <elektroschmock78@googlemail.com>2014-01-18 14:11:47 (GMT)
commit70e94740daa83c80bc76a0c57d4d8b86cf329c1e (patch)
tree9d7b42f2a8207c9fe2c4fabf4a55b60659b2c918
parent97db965535d8145eff7ac6f1bb66f2ef81c67230 (diff)
downloadandroid_packages_providers_DownloadProvider-70e94740daa83c80bc76a0c57d4d8b86cf329c1e.zip
android_packages_providers_DownloadProvider-70e94740daa83c80bc76a0c57d4d8b86cf329c1e.tar.gz
android_packages_providers_DownloadProvider-70e94740daa83c80bc76a0c57d4d8b86cf329c1e.tar.bz2
Creates parent directories before creates file
Change-Id: I124f7ce2b731b100e9572d7c5d95206e243ee316 Signed-off-by: Roger Chen <cxr514033970@gmail.com>
-rw-r--r--src/com/android/providers/downloads/Helpers.java10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index 013faf2..3562dac 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -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);