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

Side by Side 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, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <fnmatch.h> 10 #include <fnmatch.h>
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // If the destination already exists and is a directory, then the 336 // If the destination already exists and is a directory, then the
337 // top level of source needs to be copied. 337 // top level of source needs to be copied.
338 from_path_base = from_path.DirName(); 338 from_path_base = from_path.DirName();
339 } 339 }
340 340
341 // The Windows version of this function assumes that non-recursive calls 341 // The Windows version of this function assumes that non-recursive calls
342 // will always have a directory for from_path. 342 // will always have a directory for from_path.
343 DCHECK(recursive || S_ISDIR(info.stat.st_mode)); 343 DCHECK(recursive || S_ISDIR(info.stat.st_mode));
344 344
345 while (success && !current.empty()) { 345 while (success && !current.empty()) {
346 // current is the source path, including from_path, so paste 346 // current is the source path, including from_path, so append
347 // the suffix after from_path onto to_path to create the target_path. 347 // the suffix after from_path to to_path to create the target_path.
348 std::string suffix(&current.value().c_str()[from_path_base.value().size()]); 348 FilePath target_path(to_path);
349 // Strip the leading '/' (if any). 349 if (from_path_base != current) {
350 if (!suffix.empty()) { 350 if (!from_path_base.AppendRelativePath(current, &target_path)) {
351 DCHECK_EQ('/', suffix[0]); 351 success = false;
352 suffix.erase(0, 1); 352 break;
353 }
353 } 354 }
354 const FilePath target_path = to_path.Append(suffix);
355 355
356 if (S_ISDIR(info.stat.st_mode)) { 356 if (S_ISDIR(info.stat.st_mode)) {
357 if (mkdir(target_path.value().c_str(), info.stat.st_mode & 01777) != 0 && 357 if (mkdir(target_path.value().c_str(), info.stat.st_mode & 01777) != 0 &&
358 errno != EEXIST) { 358 errno != EEXIST) {
359 DLOG(ERROR) << "CopyDirectory() couldn't create directory: " 359 DLOG(ERROR) << "CopyDirectory() couldn't create directory: "
360 << target_path.value() << " errno = " << errno; 360 << target_path.value() << " errno = " << errno;
361 success = false; 361 success = false;
362 } 362 }
363 } else if (S_ISREG(info.stat.st_mode)) { 363 } else if (S_ISREG(info.stat.st_mode)) {
364 if (!CopyFile(current, target_path)) { 364 if (!CopyFile(current, target_path)) {
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 1124
1125 allowed_group_ids.insert(group_record->gr_gid); 1125 allowed_group_ids.insert(group_record->gr_gid);
1126 } 1126 }
1127 1127
1128 return VerifyPathControlledByUser( 1128 return VerifyPathControlledByUser(
1129 kFileSystemRoot, path, kRootUid, allowed_group_ids); 1129 kFileSystemRoot, path, kRootUid, allowed_group_ids);
1130 } 1130 }
1131 #endif // defined(OS_MACOSX) && !defined(OS_IOS) 1131 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
1132 1132
1133 } // namespace file_util 1133 } // namespace file_util
OLDNEW
« 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