[llvm] [Support] Handle delete_pending case for Windows fs::status (PR #90655)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Tue May 14 11:01:38 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);
----------------
efriedma-quic wrote:
The only way to get a delete_pending error is, as far as I can tell, to actually delete a file in-place. If you rename a file, then delete it, the original name should get freed immediately after the rename.
My best theory for what's actually happening is that the "rename" is actually creating its own issue: somehow, the code for renaming a file on top of an existing file actually ends up deleting the existing file in-place, leading to delete_pending errors if some other process has the file open. This seems like it should be possible to fix without sleeping...
https://github.com/llvm/llvm-project/pull/90655
More information about the llvm-commits
mailing list