[llvm] [Support] Handle delete_pending case for Windows fs::status (PR #90655)
Jeremy Day via llvm-commits
llvm-commits at lists.llvm.org
Mon May 13 09:59:59 PDT 2024
================
@@ -785,9 +785,20 @@ 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());
- if (attr == INVALID_FILE_ATTRIBUTES)
- return getStatus(INVALID_HANDLE_VALUE, result);
+ DWORD attr;
+
+ // If getting file attributes fails due to a pending deletion, try
+ // again in a loop to avoid returning a misleading permission denied
+ // error.
+ for (int Retry = 200; Retry >= 0; --Retry) {
+ attr = ::GetFileAttributesW(path_utf16.begin());
+ if (attr != INVALID_FILE_ATTRIBUTES)
+ break;
+ std::error_code code = getStatus(INVALID_HANDLE_VALUE, result);
+ if (code != llvm::errc::delete_pending || !Retry)
+ return code;
+ ::Sleep(15);
----------------
z2oh wrote:
Yes, you are reading this right. The loop here is expected to succeed within a few iterations, and if doesn't complete within the 3 second window, that's a good indication that there's probably something else awry.
But, of course, callers may be able to handle this failure case and prefer to avoid a 3 second penalty.
I'll test to see how many iterations are reached under a normal workload.
https://github.com/llvm/llvm-project/pull/90655
More information about the llvm-commits
mailing list