diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 21:39:42 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 21:39:42 +0000 |
commit | 0ba86e4c0da3770ed5e6b63b4f5121e4075bcde6 (patch) | |
tree | 0597072c14c89470a0a8fa815dda18fbf73483b0 /base | |
parent | 56ac89b4cc2d93d8cf288053a4d6b22e04b08936 (diff) | |
download | chromium_src-0ba86e4c0da3770ed5e6b63b4f5121e4075bcde6.zip chromium_src-0ba86e4c0da3770ed5e6b63b4f5121e4075bcde6.tar.gz chromium_src-0ba86e4c0da3770ed5e6b63b4f5121e4075bcde6.tar.bz2 |
POSIX: Handle race conditions in file_util::CreateDirectory where multiple processes tries to create the same file system tree simultaneously.
BUG=38112
TEST=none
Review URL: http://codereview.chromium.org/990002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41881 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/file_util_posix.cc | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index 9ab25a3..4a86261 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -429,10 +429,16 @@ bool CreateDirectory(const FilePath& full_path) { // Iterate through the parents and create the missing ones. for (std::vector<FilePath>::reverse_iterator i = subpaths.rbegin(); i != subpaths.rend(); ++i) { - if (!DirectoryExists(*i)) { - if (mkdir(i->value().c_str(), 0700) != 0) - return false; - } + if (DirectoryExists(*i)) + continue; + if (mkdir(i->value().c_str(), 0700) == 0) + continue; + // Mkdir failed, but it might have failed with EEXIST, or some other error + // due to the the directory appearing out of thin air. This can occur if + // two processes are trying to create the same file system tree at the same + // time. Check to see if it exists and make sure it is a directory. + if (!DirectoryExists(*i)) + return false; } return true; } |