Skip to content

Commit dd2cc94

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`)
1 parent 9e231f1 commit dd2cc94

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
@@ -245,7 +245,7 @@ std::optional<bool> IndexUnitWriter::isUnitUpToDateForOutputFile(
245245

246246
llvm::sys::fs::file_status UnitStat;
247247
if (std::error_code EC = llvm::sys::fs::status(UnitPath.c_str(), UnitStat)) {
248-
if (EC != llvm::errc::no_such_file_or_directory) {
248+
if (EC != llvm::errc::no_such_file_or_directory && EC != llvm::errc::delete_pending) {
249249
llvm::raw_string_ostream Err(Error);
250250
Err << "could not access path '" << UnitPath
251251
<< "': " << EC.message();
@@ -259,7 +259,7 @@ std::optional<bool> IndexUnitWriter::isUnitUpToDateForOutputFile(
259259

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

0 commit comments

Comments
 (0)