Commit 2c108cba authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

[ImportantFileWriter] Improve diagnostics on failure to replace.

On Windows, ImportantFileWriter boosts its thread's priority for the
moment it calls ::ReplaceFileW in the hopes that this will improve its
chances of beating other processes (e.g., A/V scanners) that will try to
open the files it needs. This change preserves the last error code
coming out of a failure of ::ReplaceFileW for use in logging and metrics
reporting.

BUG=1145235
R=jdoerrie@chromium.org

Change-Id: I1e275698c5c39fa7cfa97d6b3bf48e2023a8763f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2556841
Commit-Queue: Greg Thompson <grt@chromium.org>
Auto-Submit: Greg Thompson <grt@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830557}
parent 42b0b379
......@@ -274,8 +274,13 @@ bool ImportantFileWriter::WriteFileAtomicallyImpl(const FilePath& path,
tmp_file.Close();
const bool result = ReplaceFile(tmp_file_path, path, &replace_file_error);
#if defined(OS_WIN)
// Save and restore the last error code so that it's not polluted by the
// thread priority change.
const auto last_error = ::GetLastError();
if (reset_priority)
PlatformThread::SetCurrentThreadPriority(previous_priority);
if (!result)
::SetLastError(last_error);
#endif // defined(OS_WIN)
if (!result) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment