From a42fdcd4574e7011e8a0031b33ddc3490fbe99d1 Mon Sep 17 00:00:00 2001 From: "paivanof@gmail.com" Date: Wed, 5 Dec 2012 18:31:14 +0000 Subject: [PATCH] Add SHARED_DELETE flag to FileStream. Allow for all tests to do a guaranteed deletion of their temporary files (it could fail previously on Windows). TEST=net_unittests BUG= Review URL: https://chromiumcodereview.appspot.com/11440008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171257 0039d316-1c4b-4281-b951-d872f2087c98 --- net/base/file_stream_context.cc | 5 +++++ net/base/file_stream_unittest.cc | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/net/base/file_stream_context.cc b/net/base/file_stream_context.cc index 1ed7ef628ad022..1e0c157ed8c43f 100644 --- a/net/base/file_stream_context.cc +++ b/net/base/file_stream_context.cc @@ -151,6 +151,11 @@ void FileStream::Context::BeginOpenEvent(const FilePath& path) { FileStream::Context::OpenResult FileStream::Context::OpenFileImpl( const FilePath& path, int open_flags) { + // FileStream::Context actually closes the file asynchronously, independently + // from FileStream's destructor. It can cause problems for users wanting to + // delete the file right after FileStream deletion. Thus we are always + // adding SHARE_DELETE flag to accommodate such use case. + open_flags |= base::PLATFORM_FILE_SHARE_DELETE; OpenResult result; result.error_code = OK; result.file = base::CreatePlatformFile(path, open_flags, NULL, NULL); diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc index e9307cd5fd091a..731de7735759fc 100644 --- a/net/base/file_stream_unittest.cc +++ b/net/base/file_stream_unittest.cc @@ -44,7 +44,7 @@ class FileStreamTest : public PlatformTest { file_util::WriteFile(temp_file_path_, kTestData, kTestDataSize); } virtual void TearDown() { - file_util::Delete(temp_file_path_, false); + EXPECT_TRUE(file_util::Delete(temp_file_path_, false)); PlatformTest::TearDown(); }