diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-22 19:29:23 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-22 19:29:23 +0000 |
commit | ad0f81dd10c2322df4bf4dcbbe4719ea6d097a6f (patch) | |
tree | e0e0e24b9da6997137639312630800ac76434707 /base | |
parent | e7da6aefa0e6219917d8e5d098212e965c7a28ce (diff) | |
download | chromium_src-ad0f81dd10c2322df4bf4dcbbe4719ea6d097a6f.zip chromium_src-ad0f81dd10c2322df4bf4dcbbe4719ea6d097a6f.tar.gz chromium_src-ad0f81dd10c2322df4bf4dcbbe4719ea6d097a6f.tar.bz2 |
Add a flag to open files in share delete mode
BUG=86928
TEST=base_unittests
Review URL: http://codereview.chromium.org/7233007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90071 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/platform_file.h | 2 | ||||
-rw-r--r-- | base/platform_file_unittest.cc | 36 | ||||
-rw-r--r-- | base/platform_file_win.cc | 2 |
3 files changed, 40 insertions, 0 deletions
diff --git a/base/platform_file.h b/base/platform_file.h index 5b29e07..afe909a 100644 --- a/base/platform_file.h +++ b/base/platform_file.h @@ -50,6 +50,8 @@ enum PlatformFileFlags { PLATFORM_FILE_WRITE_ATTRIBUTES = 8192, // Used on Windows only PLATFORM_FILE_ENUMERATE = 16384, // May enumerate directory + + PLATFORM_FILE_SHARE_DELETE = 32768, // Used on Windows only }; // PLATFORM_FILE_ERROR_ACCESS_DENIED is returned when a call fails because of diff --git a/base/platform_file_unittest.cc b/base/platform_file_unittest.cc index 0bd4fb3..039c7ef 100644 --- a/base/platform_file_unittest.cc +++ b/base/platform_file_unittest.cc @@ -127,6 +127,42 @@ TEST(PlatformFile, CreatePlatformFile) { EXPECT_FALSE(file_util::PathExists(file_path)); } +TEST(PlatformFile, DeleteOpenFile) { + ScopedTempDir temp_dir; + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + FilePath file_path = temp_dir.path().AppendASCII("create_file_1"); + + // Create a file. + bool created = false; + base::PlatformFileError error_code = base::PLATFORM_FILE_OK; + base::PlatformFile file = base::CreatePlatformFile( + file_path, + base::PLATFORM_FILE_OPEN_ALWAYS | + base::PLATFORM_FILE_READ | + base::PLATFORM_FILE_SHARE_DELETE, + &created, &error_code); + EXPECT_NE(base::kInvalidPlatformFileValue, file); + EXPECT_TRUE(created); + EXPECT_EQ(base::PLATFORM_FILE_OK, error_code); + + // Open an existing file and mark it as delete on close. + created = false; + base::PlatformFile same_file = base::CreatePlatformFile( + file_path, + base::PLATFORM_FILE_OPEN | + base::PLATFORM_FILE_DELETE_ON_CLOSE | + base::PLATFORM_FILE_READ, + &created, &error_code); + EXPECT_NE(base::kInvalidPlatformFileValue, file); + EXPECT_FALSE(created); + EXPECT_EQ(base::PLATFORM_FILE_OK, error_code); + + // Close both handles and check that the file is gone. + base::ClosePlatformFile(file); + base::ClosePlatformFile(same_file); + EXPECT_FALSE(file_util::PathExists(file_path)); +} + TEST(PlatformFile, ReadWritePlatformFile) { ScopedTempDir temp_dir; ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); diff --git a/base/platform_file_win.cc b/base/platform_file_win.cc index f448db0..8374042 100644 --- a/base/platform_file_win.cc +++ b/base/platform_file_win.cc @@ -58,6 +58,8 @@ PlatformFile CreatePlatformFile(const FilePath& name, DWORD sharing = (flags & PLATFORM_FILE_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ; if (!(flags & PLATFORM_FILE_EXCLUSIVE_WRITE)) sharing |= FILE_SHARE_WRITE; + if (flags & PLATFORM_FILE_SHARE_DELETE) + sharing |= FILE_SHARE_DELETE; DWORD create_flags = 0; if (flags & PLATFORM_FILE_ASYNC) |