diff options
author | Jeff Sharkey <jsharkey@android.com> | 2014-01-17 11:19:58 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-01-17 11:19:58 -0800 |
commit | 18794718f15cbf79c8da732af3e8368c7b905523 (patch) | |
tree | f3131043f03af7ca6f1e54950f6f9f4e234ebc52 | |
parent | 7f13f61be97d5774516be544239bc0a0338cfb47 (diff) | |
parent | c5d43a1fc595ce650a9a20d2811ad47429ebd7da (diff) | |
download | android_packages_providers_DownloadProvider-18794718f15cbf79c8da732af3e8368c7b905523.tar.gz android_packages_providers_DownloadProvider-18794718f15cbf79c8da732af3e8368c7b905523.tar.bz2 android_packages_providers_DownloadProvider-18794718f15cbf79c8da732af3e8368c7b905523.zip |
am c5d43a1f: Merge "Creates parent directories before creates file"
* commit 'c5d43a1fc595ce650a9a20d2811ad47429ebd7da':
Creates parent directories before creates file
-rw-r--r-- | src/com/android/providers/downloads/Helpers.java | 10 |
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 013faf27..3562dac7 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); |