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

Unified Diff: base/files/file_util_win.cc

Issue 2681643005: Report more relevant error code for windows base::ReplaceFile impl (Closed)
Patch Set: Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698