summaryrefslogtreecommitdiffstats
path: root/base/file_util_win.cc
diff options
context:
space:
mode:
authormaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-15 18:48:42 +0000
committermaruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-15 18:48:42 +0000
commit87750624ea6b424e8f94c1066ae879705e6d554e (patch)
tree60760d88c08960abbfb60a8b59048041b4c589de /base/file_util_win.cc
parentd45f9bd1b4203f8846fd424d537e3de43e26155c (diff)
downloadchromium_src-87750624ea6b424e8f94c1066ae879705e6d554e.zip
chromium_src-87750624ea6b424e8f94c1066ae879705e6d554e.tar.gz
chromium_src-87750624ea6b424e8f94c1066ae879705e6d554e.tar.bz2
Make all the files mapped in when running base_unittests read only.
This means no file can be opened for write during the test run. Make CopyFileUnsafe() reset the RO bit on Windows. Add a tests that confirms the current CopyFile() behavior: - On Windows, CopyFile() copies the ACL but now strips the READONLY bit. - On OSX, CopyFile() copies the ACL. - On anything else, ACL is not copied. Rationale: On anything-but-Windows, deleting a file require write access on the directory. On Windows, deleting a file require not having the RO bit on the file. CopyFile() affects the file but not the directory. On isolated testing, the read only bit will be set on the file being copied, causing the test to fail to delete the files. This has wide implications in the unit tests. CopyFile() is mostly (but not exclusively) used in unit tests. R=thakis@chromium.org, vadimsh@chromium.org BUG=116251 Review URL: https://codereview.chromium.org/136693004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244947 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_win.cc')
-rw-r--r--base/file_util_win.cc20
1 files changed, 18 insertions, 2 deletions
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index 6ff1820..dd62825 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -728,8 +728,24 @@ bool CopyFileUnsafe(const FilePath& from_path, const FilePath& to_path) {
to_path.value().length() >= MAX_PATH) {
return false;
}
- return (::CopyFile(from_path.value().c_str(), to_path.value().c_str(),
- false) != 0);
+
+ // Unlike the posix implementation that copies the file manually and discards
+ // the ACL bits, CopyFile() copies the complete SECURITY_DESCRIPTOR and access
+ // bits, which is usually not what we want. We can't do much about the
+ // SECURITY_DESCRIPTOR but at least remove the read only bit.
+ const wchar_t* dest = to_path.value().c_str();
+ if (!::CopyFile(from_path.value().c_str(), dest, false)) {
+ // Copy failed.
+ return false;
+ }
+ DWORD attrs = GetFileAttributes(dest);
+ if (attrs == INVALID_FILE_ATTRIBUTES) {
+ return false;
+ }
+ if (attrs & FILE_ATTRIBUTE_READONLY) {
+ SetFileAttributes(dest, attrs & ~FILE_ATTRIBUTE_READONLY);
+ }
+ return true;
}
bool CopyAndDeleteDirectory(const FilePath& from_path,