Skip to content

Conversation

@ayushpareek2003
Copy link

At line 754, added a FOR loop for retrying until we get a unique path

At line 754, added a FOR loop for retrying until we get a unique path
@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 23, 2025

@llvm/pr-subscribers-clang

Author: Ayush Pareek (ayushpareek2003)

Changes

At line 754, added a FOR loop for retrying until we get a unique path


Full diff: https://github.com/llvm/llvm-project/pull/132640.diff

1 Files Affected:

  • (modified) clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp (+19-3)
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index ca15a088c308d..5527275575b26 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -750,9 +750,25 @@ bool DependencyScanningWorker::computeDependencies(
   auto InMemoryFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
   InMemoryFS->setCurrentWorkingDirectory(WorkingDirectory);
   SmallString<128> FakeInputPath;
-  // TODO: We should retry the creation if the path already exists.
-  llvm::sys::fs::createUniquePath(ModuleName + "-%%%%%%%%.input", FakeInputPath,
-                                  /*MakeAbsolute=*/false);
+  
+  unsigned RetryCount = 5; // retries to create 
+  bool UniquePathCreated = false;
+
+  for (unsigned i = 0; i < RetryCount; ++i) {
+    if (llvm::sys::fs::createUniquePath(ModuleName + "-%%%%%%%%.input", FakeInputPath,
+                                        /*MakeAbsolute=*/false)) {
+      if (!llvm::sys::fs::exists(FakeInputPath)) {
+        UniquePathCreated = true;
+        break; // Successfully created a unique path
+      }
+    }
+  }
+  if (!UniquePathCreated) {
+    llvm::errs() << "Error: Failed to create a unique input path after " 
+                 << RetryCount << " retries.\n";
+    return false; // Handle failure appropriately
+  }
+  
   InMemoryFS->addFile(FakeInputPath, 0, llvm::MemoryBuffer::getMemBuffer(""));
   llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> InMemoryOverlay = InMemoryFS;
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants