Skip to content

Commit

Permalink
[Windows] Handle some more error codes in File::OSErrorToFileError.
Browse files Browse the repository at this point in the history
- Map the bespoke ReplaceFile errors to FILE_ERROR_IN_USE, since they
  generally mean that some other entity is preventing operations on one
  or both of the files in play.
- Map LOCK_VIOLATION to FILE_ERROR_ACCESS_DENIED, since that's kinda
  what it means (the holder of the lock is denying you access, right?).
- Map GEN_FAILURE and DISK_OPERATION_FAILED to FILE_ERROR_IO, since they
  mean that something bad happened while talking to the device.

Also, add a few popular values to the WinGetLastError histogram enum.

Bug: 1175817
Change-Id: Ie7df2c3ee4cdbbbc6e013fec6a4081cfdc41b32e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3147390
Auto-Submit: Greg Thompson <[email protected]>
Reviewed-by: Wez <[email protected]>
Commit-Queue: Greg Thompson <[email protected]>
Cr-Commit-Position: refs/heads/main@{#919435}
  • Loading branch information
GregTho authored and Chromium LUCI CQ committed Sep 8, 2021
1 parent 64a82a9 commit 18e8500
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 11 additions & 5 deletions base/files/file_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ bool File::DeleteOnClose(bool delete_on_close) {
File::Error File::OSErrorToFileError(DWORD last_error) {
switch (last_error) {
case ERROR_SHARING_VIOLATION:
case ERROR_UNABLE_TO_REMOVE_REPLACED: // ReplaceFile failure cases.
case ERROR_UNABLE_TO_MOVE_REPLACEMENT:
case ERROR_UNABLE_TO_MOVE_REPLACEMENT_2:
return FILE_ERROR_IN_USE;
case ERROR_ALREADY_EXISTS:
case ERROR_FILE_EXISTS:
Expand All @@ -315,6 +318,7 @@ File::Error File::OSErrorToFileError(DWORD last_error) {
case ERROR_PATH_NOT_FOUND:
return FILE_ERROR_NOT_FOUND;
case ERROR_ACCESS_DENIED:
case ERROR_LOCK_VIOLATION:
return FILE_ERROR_ACCESS_DENIED;
case ERROR_TOO_MANY_OPEN_FILES:
return FILE_ERROR_TOO_MANY_OPENED;
Expand All @@ -327,12 +331,14 @@ File::Error File::OSErrorToFileError(DWORD last_error) {
return FILE_ERROR_NO_SPACE;
case ERROR_USER_MAPPED_FILE:
return FILE_ERROR_INVALID_OPERATION;
case ERROR_NOT_READY:
case ERROR_SECTOR_NOT_FOUND:
case ERROR_DEV_NOT_EXIST:
case ERROR_NOT_READY: // The device is not ready.
case ERROR_SECTOR_NOT_FOUND: // The drive cannot find the sector requested.
case ERROR_GEN_FAILURE: // A device ... is not functioning.
case ERROR_DEV_NOT_EXIST: // Net resource or device is no longer available.
case ERROR_IO_DEVICE:
case ERROR_FILE_CORRUPT:
case ERROR_DISK_CORRUPT:
case ERROR_DISK_OPERATION_FAILED:
case ERROR_FILE_CORRUPT: // File or directory is corrupted and unreadable.
case ERROR_DISK_CORRUPT: // The disk structure is corrupted and unreadable.
return FILE_ERROR_IO;
default:
UmaHistogramSparse("PlatformFile.UnknownErrors.Windows", last_error);
Expand Down
6 changes: 6 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90901,7 +90901,12 @@ Called by update_scheduler_enums.py.-->
<int value="999" label="SWAPERROR"/>
<int value="1011" label="ERROR_CANTOPEN"/>
<int value="1117" label="ERROR_IO_DEVICE"/>
<int value="1127" label="DISK_OPERATION_FAILED"/>
<int value="1175" label="UNABLE_TO_REMOVE_REPLACED"/>
<int value="1176" label="UNABLE_TO_MOVE_REPLACEMENT"/>
<int value="1177" label="UNABLE_TO_MOVE_REPLACEMENT_2"/>
<int value="1223" label="ERROR_CANCELLED"/>
<int value="1296" label="CONTENT_BLOCKED"/>
<int value="1346" label="ERROR_BAD_IMPERSONATION_LEVEL"/>
<int value="1392" label="ERROR_FILE_CORRUPT"/>
<int value="1393" label="ERROR_DISK_CORRUPT"/>
Expand All @@ -90915,6 +90920,7 @@ Called by update_scheduler_enums.py.-->
<int value="1784" label="INVALID_USER_BUFFER"/>
<int value="1816" label="NOT_ENOUGH_QUOTA"/>
<int value="1818" label="RPC_S_CALL_CANCELLED"/>
<int value="1920" label="CANT_ACCESS_FILE"/>
<int value="6000" label="ERROR_ENCRYPTION_FAILED"/>
<int value="6001" label="ERROR_DECRYPTION_FAILED"/>
<int value="7041" label="ERROR_CTX_CONSOLE_DISCONNECT"/>
Expand Down

0 comments on commit 18e8500

Please sign in to comment.