Chromium Code Reviews| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 if (rename(from_path.value().c_str(), to_path.value().c_str()) == 0) | 225 if (rename(from_path.value().c_str(), to_path.value().c_str()) == 0) |
| 226 return true; | 226 return true; |
| 227 | 227 |
| 228 if (!CopyDirectory(from_path, to_path, true)) | 228 if (!CopyDirectory(from_path, to_path, true)) |
| 229 return false; | 229 return false; |
| 230 | 230 |
| 231 Delete(from_path, true); | 231 Delete(from_path, true); |
| 232 return true; | 232 return true; |
| 233 } | 233 } |
| 234 | 234 |
| 235 bool ReplaceFile(const FilePath& from_path, const FilePath& to_path) { | 235 bool ReplaceFile(const FilePath& from_path, const FilePath& to_path, |
| 236 base::PlatformFileError* error) { | |
| 237 if (error) | |
| 238 *error = base::PLATFORM_FILE_OK; | |
| 236 base::ThreadRestrictions::AssertIOAllowed(); | 239 base::ThreadRestrictions::AssertIOAllowed(); |
| 237 return (rename(from_path.value().c_str(), to_path.value().c_str()) == 0); | 240 if (rename(from_path.value().c_str(), to_path.value().c_str()) != 0) { |
| 241 if (error) | |
| 242 *error = base::ErrnoToPlatformFileError(errno); | |
| 243 return false; | |
| 244 } | |
| 245 return true; | |
|
jar (doing other things)
2013/05/07 01:12:36
nit: switch the order of the results around, and y
| |
| 238 } | 246 } |
| 239 | 247 |
| 240 bool CopyDirectory(const FilePath& from_path, | 248 bool CopyDirectory(const FilePath& from_path, |
| 241 const FilePath& to_path, | 249 const FilePath& to_path, |
| 242 bool recursive) { | 250 bool recursive) { |
| 243 base::ThreadRestrictions::AssertIOAllowed(); | 251 base::ThreadRestrictions::AssertIOAllowed(); |
| 244 // Some old callers of CopyDirectory want it to support wildcards. | 252 // Some old callers of CopyDirectory want it to support wildcards. |
| 245 // After some discussion, we decided to fix those callers. | 253 // After some discussion, we decided to fix those callers. |
| 246 // Break loudly here if anyone tries to do this. | 254 // Break loudly here if anyone tries to do this. |
| 247 // TODO(evanm): remove this once we're sure it's ok. | 255 // TODO(evanm): remove this once we're sure it's ok. |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 kFileSystemRoot, path, kRootUid, allowed_group_ids); | 1069 kFileSystemRoot, path, kRootUid, allowed_group_ids); |
| 1062 } | 1070 } |
| 1063 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 1071 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 1064 | 1072 |
| 1065 int GetMaximumPathComponentLength(const FilePath& path) { | 1073 int GetMaximumPathComponentLength(const FilePath& path) { |
| 1066 base::ThreadRestrictions::AssertIOAllowed(); | 1074 base::ThreadRestrictions::AssertIOAllowed(); |
| 1067 return pathconf(path.value().c_str(), _PC_NAME_MAX); | 1075 return pathconf(path.value().c_str(), _PC_NAME_MAX); |
| 1068 } | 1076 } |
| 1069 | 1077 |
| 1070 } // namespace file_util | 1078 } // namespace file_util |
| OLD | NEW |