Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f2d9391b authored by Christopher Tate's avatar Christopher Tate Committed by Android Git Automerger
Browse files

am 64884eef: am b61c8219: am ef4f8222: Merge "Fix cross-process race in...

am 64884eef: am b61c8219: am ef4f8222: Merge "Fix cross-process race in initial files/cache dir creation" into klp-dev

* commit '64884eef':
  Fix cross-process race in initial files/cache dir creation
parents 38dc2ad8 64884eef
Loading
Loading
Loading
Loading
+23 −12
Original line number Original line Diff line number Diff line
@@ -817,6 +817,10 @@ class ContextImpl extends Context {
            }
            }
            if (!mFilesDir.exists()) {
            if (!mFilesDir.exists()) {
                if(!mFilesDir.mkdirs()) {
                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());
                    Log.w(TAG, "Unable to create files directory " + mFilesDir.getPath());
                    return null;
                    return null;
                }
                }
@@ -879,6 +883,10 @@ class ContextImpl extends Context {
            }
            }
            if (!mCacheDir.exists()) {
            if (!mCacheDir.exists()) {
                if(!mCacheDir.mkdirs()) {
                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());
                    Log.w(TAG, "Unable to create cache directory " + mCacheDir.getAbsolutePath());
                    return null;
                    return null;
                }
                }
@@ -2136,6 +2144,8 @@ class ContextImpl extends Context {
            File dir = dirs[i];
            File dir = dirs[i];
            if (!dir.exists()) {
            if (!dir.exists()) {
                if (!dir.mkdirs()) {
                if (!dir.mkdirs()) {
                    // recheck existence in case of cross-process race
                    if (!dir.exists()) {
                        // Failing to mkdir() may be okay, since we might not have
                        // Failing to mkdir() may be okay, since we might not have
                        // enough permissions; ask vold to create on our behalf.
                        // enough permissions; ask vold to create on our behalf.
                        final IMountService mount = IMountService.Stub.asInterface(
                        final IMountService mount = IMountService.Stub.asInterface(
@@ -2151,6 +2161,7 @@ class ContextImpl extends Context {
                        }
                        }
                    }
                    }
                }
                }
            }
            result[i] = dir;
            result[i] = dir;
        }
        }
        return result;
        return result;