From 0c5c644eeee2739c68acdd1cd6c55a8e1aaeb3a3 Mon Sep 17 00:00:00 2001 From: Jeremy Day Date: Tue, 4 Jun 2024 10:55:27 -0700 Subject: [PATCH] Handle new `delete_pending` error code when stating index unit files Multiple clang processes race to write out the same index file via renaming a newly generated index file ontop of the stale one. On Windows, there is a small window where the destination path is marked for deletion, and querying the file at this time would return a misleading `permission_denied` error (which is the Win32 error mapping from the underlying NTSTATUS code `STATUS_DELETE_PENDING`). An upstream change has modified the `fs::status` function on Windows to detect this case and return a more accurate `delete_pending` error code, which can be handled here as if the file is already deleted (i.e. `no_such_file_or_directory`) (cherry picked from commit dd2cc940551f22c732803ccedda467bbf7228de6) --- clang/lib/Index/IndexUnitWriter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Index/IndexUnitWriter.cpp b/clang/lib/Index/IndexUnitWriter.cpp index f1b594d4044b9..3f1f4b4858b03 100644 --- a/clang/lib/Index/IndexUnitWriter.cpp +++ b/clang/lib/Index/IndexUnitWriter.cpp @@ -242,7 +242,7 @@ std::optional IndexUnitWriter::isUnitUpToDateForOutputFile( llvm::sys::fs::file_status UnitStat; if (std::error_code EC = llvm::sys::fs::status(UnitPath.c_str(), UnitStat)) { - if (EC != llvm::errc::no_such_file_or_directory) { + if (EC != llvm::errc::no_such_file_or_directory && EC != llvm::errc::delete_pending) { llvm::raw_string_ostream Err(Error); Err << "could not access path '" << UnitPath << "': " << EC.message(); @@ -256,7 +256,7 @@ std::optional IndexUnitWriter::isUnitUpToDateForOutputFile( llvm::sys::fs::file_status CompareStat; if (std::error_code EC = llvm::sys::fs::status(*TimeCompareFilePath, CompareStat)) { - if (EC != llvm::errc::no_such_file_or_directory) { + if (EC != llvm::errc::no_such_file_or_directory && EC != llvm::errc::delete_pending) { llvm::raw_string_ostream Err(Error); Err << "could not access path '" << *TimeCompareFilePath << "': " << EC.message();