Chromium Code Reviews| Index: base/files/file_util_win.cc |
| diff --git a/base/files/file_util_win.cc b/base/files/file_util_win.cc |
| index 4e67b5a348653f3af41d897f845ce4e0df4f2571..9cb446bc87ce581cdb7088551c72ec0d134d2334 100644 |
| --- a/base/files/file_util_win.cc |
| +++ b/base/files/file_util_win.cc |
| @@ -134,6 +134,8 @@ bool ReplaceFile(const FilePath& from_path, |
| // already exist. |
| if (::MoveFile(from_path.value().c_str(), to_path.value().c_str())) |
| return true; |
| + File::Error move_error = File::OSErrorToFileError(GetLastError()); |
|
dcheng
2017/02/07 23:24:50
DWORD error_code = ::GetLastError();
|
| + |
| // Try the full-blown replace if the move fails, as ReplaceFile will only |
| // succeed when |to_path| does exist. When writing to a network share, we may |
| // not be able to change the ACLs. Ignore ACL errors then |
| @@ -142,8 +144,14 @@ bool ReplaceFile(const FilePath& from_path, |
| REPLACEFILE_IGNORE_MERGE_ERRORS, NULL, NULL)) { |
| return true; |
| } |
| - if (error) |
| - *error = File::OSErrorToFileError(GetLastError()); |
| + // In the case of FILE_ERROR_NOT_FOUND from ReplaceFile, it is likely that |
| + // |to_path| does not exist. In this case, the more relevant error comes |
| + // from the call to MoveFile. |
| + if (error) { |
| + File::Error replace_error = File::OSErrorToFileError(GetLastError()); |
| + *error = replace_error == File::FILE_ERROR_NOT_FOUND ? move_error |
|
dcheng
2017/02/07 23:24:50
if ((replace_error = ::GetLastError()) != ERROR_FI
Charlie Harrison
2017/02/07 23:31:23
Going to push back on this, only because I think i
dcheng
2017/02/07 23:32:39
Makes sense, I'm OK with that.
|
| + : replace_error; |
| + } |
| return false; |
| } |