diff options
author | Roger Chen <cxr514033970@gmail.com> | 2014-01-03 14:37:26 +0800 |
---|---|---|
committer | Kim Le <elektroschmock78@googlemail.com> | 2014-01-20 18:06:59 +0000 |
commit | 8800dbd05e96b663b98c5b65244c6e8cf24c9291 (patch) | |
tree | 06c5bb6535345f5712f55c13b6348f4c3a83df31 | |
parent | 34b1e29a3fd013c24c968c48366a3cb3bb50592d (diff) | |
download | android_packages_providers_DownloadProvider-cm-10.2.tar.gz android_packages_providers_DownloadProvider-cm-10.2.tar.bz2 android_packages_providers_DownloadProvider-cm-10.2.zip |
Creates parent directories before creates filecm-10.2
Change-Id: I124f7ce2b731b100e9572d7c5d95206e243ee316
Signed-off-by: Roger Chen <cxr514033970@gmail.com>
(cherry picked from commit 70e94740daa83c80bc76a0c57d4d8b86cf329c1e)
-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 33205557..007e663a 100644 --- a/src/com/android/providers/downloads/Helpers.java +++ b/src/com/android/providers/downloads/Helpers.java @@ -139,7 +139,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); |