Skip to content

Commit 3927b90

Browse files
Retry for Unique Path Creation
At line 754, added a FOR loop for retrying until we get a unique path
1 parent 06fd10f commit 3927b90

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,25 @@ bool DependencyScanningWorker::computeDependencies(
750750
auto InMemoryFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
751751
InMemoryFS->setCurrentWorkingDirectory(WorkingDirectory);
752752
SmallString<128> FakeInputPath;
753-
// TODO: We should retry the creation if the path already exists.
754-
llvm::sys::fs::createUniquePath(ModuleName + "-%%%%%%%%.input", FakeInputPath,
755-
/*MakeAbsolute=*/false);
753+
754+
unsigned RetryCount = 5; // retries to create
755+
bool UniquePathCreated = false;
756+
757+
for (unsigned i = 0; i < RetryCount; ++i) {
758+
if (llvm::sys::fs::createUniquePath(ModuleName + "-%%%%%%%%.input", FakeInputPath,
759+
/*MakeAbsolute=*/false)) {
760+
if (!llvm::sys::fs::exists(FakeInputPath)) {
761+
UniquePathCreated = true;
762+
break; // Successfully created a unique path
763+
}
764+
}
765+
}
766+
if (!UniquePathCreated) {
767+
llvm::errs() << "Error: Failed to create a unique input path after "
768+
<< RetryCount << " retries.\n";
769+
return false; // Handle failure appropriately
770+
}
771+
756772
InMemoryFS->addFile(FakeInputPath, 0, llvm::MemoryBuffer::getMemBuffer(""));
757773
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> InMemoryOverlay = InMemoryFS;
758774

0 commit comments

Comments
 (0)