Index: base/files/file_util_win.cc |
diff --git a/base/files/file_util_win.cc b/base/files/file_util_win.cc |
index 733c32c27da220e47d4cab076a89a08430ad6b09..b511d3cc8cd4ab067319558fa6269ecde2a4bbef 100644 |
--- a/base/files/file_util_win.cc |
+++ b/base/files/file_util_win.cc |
@@ -210,7 +210,7 @@ bool CopyDirectory(const FilePath& from_path, const FilePath& to_path, |
<< target_path.value().c_str(); |
success = false; |
} |
- } else if (!internal::CopyFileUnsafe(current, target_path)) { |
+ } else if (!CopyFile(current, target_path)) { |
DLOG(ERROR) << "CopyDirectory() couldn't create file: " |
<< target_path.value().c_str(); |
success = false; |
@@ -722,6 +722,37 @@ int GetMaximumPathComponentLength(const FilePath& path) { |
return std::min(whole_path_limit, static_cast<int>(max_length)); |
} |
+bool CopyFile(const FilePath& from_path, const FilePath& to_path) { |
+ ThreadRestrictions::AssertIOAllowed(); |
+ if (from_path.ReferencesParent() || to_path.ReferencesParent()) |
+ return false; |
+ |
+ // NOTE: I suspect we could support longer paths, but that would involve |
+ // analyzing all our usage of files. |
+ if (from_path.value().length() >= MAX_PATH || |
+ to_path.value().length() >= MAX_PATH) { |
+ return false; |
+ } |
+ |
+ // 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; |
+} |
+ |
// ----------------------------------------------------------------------------- |
namespace internal { |
@@ -760,35 +791,6 @@ bool MoveUnsafe(const FilePath& from_path, const FilePath& to_path) { |
return ret; |
} |
-bool CopyFileUnsafe(const FilePath& from_path, const FilePath& to_path) { |
- ThreadRestrictions::AssertIOAllowed(); |
- |
- // NOTE: I suspect we could support longer paths, but that would involve |
- // analyzing all our usage of files. |
- if (from_path.value().length() >= MAX_PATH || |
- to_path.value().length() >= MAX_PATH) { |
- return false; |
- } |
- |
- // 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, |
const FilePath& to_path) { |
ThreadRestrictions::AssertIOAllowed(); |