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

Unified Diff: base/file_util_posix.cc

Issue 270086: Match Window's behavior when recursively copying directories that exist. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 2 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
===================================================================
--- base/file_util_posix.cc (revision 28742)
+++ base/file_util_posix.cc (working copy)
@@ -227,9 +227,18 @@
traverse_type | FileEnumerator::DIRECTORIES);
FileEnumerator traversal(from_path, recursive, traverse_type);
- // to_path may not exist yet, start the loop with to_path
+ // We have to mimic windows behavoir here. |to_path| may not exist yet,
sgk 2009/10/13 17:49:13 Nit: "behavior"
+ // start the loop with |to_path|. If this is a recrursive copy and
sgk 2009/10/13 17:49:13 Nit: "recursive"
+ // the destination already exists, we have to copy the source directory
+ // as well.
FileEnumerator::FindInfo info;
FilePath current = from_path;
+ FilePath from_path_base = from_path;
+ if (recursive && stat(to_path.value().c_str(), &info.stat) == 0) {
+ // If the destination already exists, then the top level of source
+ // needs to be copied.
+ from_path_base = from_path.DirName();
+ }
if (stat(from_path.value().c_str(), &info.stat) < 0) {
LOG(ERROR) << "CopyDirectory() couldn't stat source directory: " <<
from_path.value() << " errno = " << errno;
@@ -239,7 +248,7 @@
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.value().size()]);
+ std::string suffix(&current.value().c_str()[from_path_base.value().size()]);
// Strip the leading '/' (if any).
if (!suffix.empty()) {
DCHECK_EQ('/', suffix[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