Skip to content

Commit 0c5c644

Browse files
committed
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 dd2cc94)
1 parent c7c87ee commit 0c5c644

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

clang/lib/Index/IndexUnitWriter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ std::optional<bool> IndexUnitWriter::isUnitUpToDateForOutputFile(
242242

243243
llvm::sys::fs::file_status UnitStat;
244244
if (std::error_code EC = llvm::sys::fs::status(UnitPath.c_str(), UnitStat)) {
245-
if (EC != llvm::errc::no_such_file_or_directory) {
245+
if (EC != llvm::errc::no_such_file_or_directory && EC != llvm::errc::delete_pending) {
246246
llvm::raw_string_ostream Err(Error);
247247
Err << "could not access path '" << UnitPath
248248
<< "': " << EC.message();
@@ -256,7 +256,7 @@ std::optional<bool> IndexUnitWriter::isUnitUpToDateForOutputFile(
256256

257257
llvm::sys::fs::file_status CompareStat;
258258
if (std::error_code EC = llvm::sys::fs::status(*TimeCompareFilePath, CompareStat)) {
259-
if (EC != llvm::errc::no_such_file_or_directory) {
259+
if (EC != llvm::errc::no_such_file_or_directory && EC != llvm::errc::delete_pending) {
260260
llvm::raw_string_ostream Err(Error);
261261
Err << "could not access path '" << *TimeCompareFilePath
262262
<< "': " << EC.message();

0 commit comments

Comments
 (0)