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 ReplaceFileAndGetError(const FilePath& from_path, |
| 236 const FilePath& to_path, |
| 237 base::PlatformFileError* error) { |
236 base::ThreadRestrictions::AssertIOAllowed(); | 238 base::ThreadRestrictions::AssertIOAllowed(); |
237 return (rename(from_path.value().c_str(), to_path.value().c_str()) == 0); | 239 if (rename(from_path.value().c_str(), to_path.value().c_str()) == 0) |
| 240 return true; |
| 241 if (error) |
| 242 *error = base::ErrnoToPlatformFileError(errno); |
| 243 return false; |
238 } | 244 } |
239 | 245 |
240 bool CopyDirectory(const FilePath& from_path, | 246 bool CopyDirectory(const FilePath& from_path, |
241 const FilePath& to_path, | 247 const FilePath& to_path, |
242 bool recursive) { | 248 bool recursive) { |
243 base::ThreadRestrictions::AssertIOAllowed(); | 249 base::ThreadRestrictions::AssertIOAllowed(); |
244 // Some old callers of CopyDirectory want it to support wildcards. | 250 // Some old callers of CopyDirectory want it to support wildcards. |
245 // After some discussion, we decided to fix those callers. | 251 // After some discussion, we decided to fix those callers. |
246 // Break loudly here if anyone tries to do this. | 252 // Break loudly here if anyone tries to do this. |
247 // TODO(evanm): remove this once we're sure it's ok. | 253 // 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); | 1067 kFileSystemRoot, path, kRootUid, allowed_group_ids); |
1062 } | 1068 } |
1063 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 1069 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
1064 | 1070 |
1065 int GetMaximumPathComponentLength(const FilePath& path) { | 1071 int GetMaximumPathComponentLength(const FilePath& path) { |
1066 base::ThreadRestrictions::AssertIOAllowed(); | 1072 base::ThreadRestrictions::AssertIOAllowed(); |
1067 return pathconf(path.value().c_str(), _PC_NAME_MAX); | 1073 return pathconf(path.value().c_str(), _PC_NAME_MAX); |
1068 } | 1074 } |
1069 | 1075 |
1070 } // namespace file_util | 1076 } // namespace file_util |
OLD | NEW |