summaryrefslogtreecommitdiffstats
path: root/base/file_util_unittest.cc
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-27 14:54:41 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-27 14:54:41 +0000
commit40676ab2827e430e5719b1646aa66e9d07bc37fe (patch)
treeb834300c695262c197c9bdee513c6bdc36b18b9c /base/file_util_unittest.cc
parent0a58d6e6bb2c7ade36950ff0f8520dd9555ca044 (diff)
downloadchromium_src-40676ab2827e430e5719b1646aa66e9d07bc37fe.zip
chromium_src-40676ab2827e430e5719b1646aa66e9d07bc37fe.tar.gz
chromium_src-40676ab2827e430e5719b1646aa66e9d07bc37fe.tar.bz2
Fix race in directory creation on Windows. The
file_util::CreateDirectory() function is supposed to succeed if the directory already exists, but in the previous implementation when two processes/threads called the function at the same time for the same path, one would see a failure. Also, get rid of the use of SHCreateDirectoryEx function. For one, it is highly serializing because it calls SHChangeNotify. The race was actually easy to reproduce by starting two instances of Chrome both at the same time, with a profile directory flag indicating a profile directory that did not previously exist. For another, SHCreateDirectoryEx would fail with ERROR_CANCELLED if any of the path components were not visible, according to its MSDN documentation. BUG=none TEST=[base_unittests.exe --gtest_filter=*CreateDirectory* ], and/or install Chrome Frame on a fresh machine and make sure the first page you navigate to has two Chrome Frame instances on it - you should get no DCHECK on failure of PathService::Override Review URL: http://codereview.chromium.org/437090 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33225 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_unittest.cc')
-rw-r--r--base/file_util_unittest.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 6d57e2c..7296113 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -1137,6 +1137,23 @@ TEST_F(FileUtilTest, CreateDirectoryTest) {
EXPECT_TRUE(file_util::Delete(test_root, true));
EXPECT_FALSE(file_util::PathExists(test_root));
EXPECT_FALSE(file_util::PathExists(test_path));
+
+ // Verify assumptions made by the Windows implementation:
+ // 1. The current directory always exists.
+ // 2. The root directory always exists.
+ ASSERT_TRUE(file_util::DirectoryExists(
+ FilePath(FilePath::kCurrentDirectory)));
+ FilePath top_level = test_root;
+ while (top_level != top_level.DirName()) {
+ top_level = top_level.DirName();
+ }
+ ASSERT_TRUE(file_util::DirectoryExists(top_level));
+
+ // Given these assumptions hold, it should be safe to
+ // test that "creating" these directories succeeds.
+ EXPECT_TRUE(file_util::CreateDirectory(
+ FilePath(FilePath::kCurrentDirectory)));
+ EXPECT_TRUE(file_util::CreateDirectory(top_level));
}
TEST_F(FileUtilTest, DetectDirectoryTest) {