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

Unified Diff: base/file_util_posix.cc

Issue 11773018: Fix creating target paths in file_util_posix CopyDirectory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: support trailing separators in windows file_util::CopyDirectory Created 7 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 | « no previous file | base/file_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_posix.cc
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 0ffa6247a2f048b8039161d8eaf56e9d55097505..49cf873186d783a5251cf75fff7b45f9e6eb61de 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -343,15 +343,15 @@ bool CopyDirectory(const FilePath& from_path,
DCHECK(recursive || S_ISDIR(info.stat.st_mode));
while (success && !current.empty()) {
- // current is the source path, including from_path, so paste
- // the suffix after from_path onto to_path to create the target_path.
- std::string suffix(&current.value().c_str()[from_path_base.value().size()]);
- // Strip the leading '/' (if any).
- if (!suffix.empty()) {
- DCHECK_EQ('/', suffix[0]);
- suffix.erase(0, 1);
+ // current is the source path, including from_path, so append
+ // the suffix after from_path to to_path to create the target_path.
+ FilePath target_path(to_path);
+ if (from_path_base != current) {
+ if (!from_path_base.AppendRelativePath(current, &target_path)) {
+ success = false;
+ break;
+ }
}
- const FilePath target_path = to_path.Append(suffix);
if (S_ISDIR(info.stat.st_mode)) {
if (mkdir(target_path.value().c_str(), info.stat.st_mode & 01777) != 0 &&
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698