Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2706)

Unified Diff: base/file_util_win.cc

Issue 136693004: Make all the files mapped in when running base_unittests read only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix CopyFile() on Windows Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/base_unittests.isolate ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_win.cc
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index 6ff1820a0bc3555ed8c4baeb259ead5b9b228c01..edcec535a472ff3161e81a7ed82b20734732d55e 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 (0 == ::CopyFile(from_path.value().c_str(), dest, false)) {
Nico 2014/01/14 02:30:33 nit: `::CopyFile(...) == 0`; no yoda conditions in
M-A Ruel 2014/01/14 14:59:39 Done.
+ // Copy failed.
+ return false;
+ }
+ DWORD attrs = GetFileAttributes(dest);
+ if (attrs==INVALID_FILE_ATTRIBUTES) {
Nico 2014/01/14 02:30:33 nit: spaces around ==
M-A Ruel 2014/01/14 14:59:39 Done.
+ return false;
+ }
+ if (attrs & FILE_ATTRIBUTE_READONLY) {
+ SetFileAttributes(dest, attrs & ~FILE_ATTRIBUTE_READONLY);
+ }
+ return true;
}
bool CopyAndDeleteDirectory(const FilePath& from_path,
« no previous file with comments | « base/base_unittests.isolate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698