OLD | NEW |
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 Loading... |
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 append | 346 // current is the source path, including from_path, so paste |
347 // the suffix after from_path to to_path to create the target_path. | 347 // the suffix after from_path onto to_path to create the target_path. |
348 FilePath target_path(to_path); | 348 std::string suffix(¤t.value().c_str()[from_path_base.value().size()]); |
349 if (from_path_base != current) { | 349 // Strip the leading '/' (if any). |
350 if (!from_path_base.AppendRelativePath(current, &target_path)) { | 350 if (!suffix.empty()) { |
351 success = false; | 351 DCHECK_EQ('/', suffix[0]); |
352 break; | 352 suffix.erase(0, 1); |
353 } | |
354 } | 353 } |
| 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 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 | 1152 |
1153 allowed_group_ids.insert(group_record->gr_gid); | 1153 allowed_group_ids.insert(group_record->gr_gid); |
1154 } | 1154 } |
1155 | 1155 |
1156 return VerifyPathControlledByUser( | 1156 return VerifyPathControlledByUser( |
1157 kFileSystemRoot, path, kRootUid, allowed_group_ids); | 1157 kFileSystemRoot, path, kRootUid, allowed_group_ids); |
1158 } | 1158 } |
1159 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 1159 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
1160 | 1160 |
1161 } // namespace file_util | 1161 } // namespace file_util |
OLD | NEW |