[llvm] [Support] Handle delete_pending case for Windows fs::status (PR #90655)
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 14:29:18 PDT 2024
================
@@ -786,8 +796,28 @@ std::error_code status(const Twine &path, file_status &result, bool Follow) {
DWORD Flags = FILE_FLAG_BACKUP_SEMANTICS;
if (!Follow) {
DWORD attr = ::GetFileAttributesW(path_utf16.begin());
----------------
aganea wrote:
WDYT about moving the "delete pending" check into `llvm::mapWindowsError()`
```
std::error_code llvm::mapWindowsError(unsigned EV) {
// Special case
if (EV == ERROR_ACCESS_DENIED) {
llvm::errc code = RtlGetLastNtStatus() == STATUS_DELETE_PENDING
? errc::delete_pending
: errc::permission_denied;
return make_error_code(code);
}
switch (EV) {
MAP_ERR_TO_COND(ERROR_ALREADY_EXISTS, file_exists);
MAP_ERR_TO_COND(ERROR_BAD_NETPATH, no_such_file_or_directory);
...
```
and then shorten this loop a bit?
```
for (int Retry = 200; Retry >= 0; --Retry) {
attr = ::GetFileAttributesW(path_utf16.begin());
if (attr != INVALID_FILE_ATTRIBUTES)
break;
llvm::errc code = getStatus(INVALID_HANDLE_VALUE, result);
if (code != llvm::errc::delete_pending || !Retry)
return code;
::Sleep(10);
}
```
Also, add maybe a comment above to the effect of "we're calling this internal NT API here after `GetLastError()` because it retrieves a more precise error code after internal kernel calls".
https://github.com/llvm/llvm-project/pull/90655
More information about the llvm-commits
mailing list