summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorChristopher Tate <ctate@google.com>2013-10-03 01:58:47 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-10-03 01:58:47 +0000
commitef4f8222fc671d2453e4bcb35978afdfa9734b78 (patch)
treefc36284010f1de70930ee816c2984c2b953c5139 /core/java
parentd65825ab1cdbfd88122beaaad8cf815434cbf46d (diff)
parentcc866da37db53df67e9b324815d6377bbd47d71b (diff)
Merge "Fix cross-process race in initial files/cache dir creation" into klp-dev
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/ContextImpl.java35
1 files changed, 23 insertions, 12 deletions
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 300424cbf871..71831791b07c 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -817,6 +817,10 @@ class ContextImpl extends Context {
}
if (!mFilesDir.exists()) {
if(!mFilesDir.mkdirs()) {
+ if (mFilesDir.exists()) {
+ // spurious failure; probably racing with another process for this app
+ return mFilesDir;
+ }
Log.w(TAG, "Unable to create files directory " + mFilesDir.getPath());
return null;
}
@@ -879,6 +883,10 @@ class ContextImpl extends Context {
}
if (!mCacheDir.exists()) {
if(!mCacheDir.mkdirs()) {
+ if (mCacheDir.exists()) {
+ // spurious failure; probably racing with another process for this app
+ return mCacheDir;
+ }
Log.w(TAG, "Unable to create cache directory " + mCacheDir.getAbsolutePath());
return null;
}
@@ -2136,18 +2144,21 @@ class ContextImpl extends Context {
File dir = dirs[i];
if (!dir.exists()) {
if (!dir.mkdirs()) {
- // Failing to mkdir() may be okay, since we might not have
- // enough permissions; ask vold to create on our behalf.
- final IMountService mount = IMountService.Stub.asInterface(
- ServiceManager.getService("mount"));
- int res = -1;
- try {
- res = mount.mkdirs(getPackageName(), dir.getAbsolutePath());
- } catch (RemoteException e) {
- }
- if (res != 0) {
- Log.w(TAG, "Failed to ensure directory: " + dir);
- dir = null;
+ // recheck existence in case of cross-process race
+ if (!dir.exists()) {
+ // Failing to mkdir() may be okay, since we might not have
+ // enough permissions; ask vold to create on our behalf.
+ final IMountService mount = IMountService.Stub.asInterface(
+ ServiceManager.getService("mount"));
+ int res = -1;
+ try {
+ res = mount.mkdirs(getPackageName(), dir.getAbsolutePath());
+ } catch (RemoteException e) {
+ }
+ if (res != 0) {
+ Log.w(TAG, "Failed to ensure directory: " + dir);
+ dir = null;
+ }
}
}
}