[llvm] 295eb54 - [llvm] Don't create the directory hierarchy in the FileCollector...

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 11:21:47 PDT 2020


Author: Jonas Devlieghere
Date: 2020-08-17T11:21:39-07:00
New Revision: 295eb54deb8784e448b73eec5eb1517b27d89541

URL: https://github.com/llvm/llvm-project/commit/295eb54deb8784e448b73eec5eb1517b27d89541
DIFF: https://github.com/llvm/llvm-project/commit/295eb54deb8784e448b73eec5eb1517b27d89541.diff

LOG: [llvm] Don't create the directory hierarchy in the FileCollector...

... if the collected file doesn't exists.

This fixes the situation where LLDB can't create a file when capturing a
reproducer because the parent path doesn't exist, but can during replay
because the file collector created the directory hierarchy even though
the file doesn't exist.

This is covered by the lldb reproducer test suite.

Added: 
    

Modified: 
    llvm/lib/Support/FileCollector.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/FileCollector.cpp b/llvm/lib/Support/FileCollector.cpp
index 59755556a5a3..4c72f2b0ae90 100644
--- a/llvm/lib/Support/FileCollector.cpp
+++ b/llvm/lib/Support/FileCollector.cpp
@@ -158,14 +158,6 @@ std::error_code FileCollector::copyFiles(bool StopOnError) {
   std::lock_guard<std::mutex> lock(Mutex);
 
   for (auto &entry : VFSWriter.getMappings()) {
-    // Create directory tree.
-    if (std::error_code EC =
-            sys::fs::create_directories(sys::path::parent_path(entry.RPath),
-                                        /*IgnoreExisting=*/true)) {
-      if (StopOnError)
-        return EC;
-    }
-
     // Get the status of the original file/directory.
     sys::fs::file_status Stat;
     if (std::error_code EC = sys::fs::status(entry.VPath, Stat)) {
@@ -174,6 +166,18 @@ std::error_code FileCollector::copyFiles(bool StopOnError) {
       continue;
     }
 
+    // Continue if the file doesn't exist.
+    if (Stat.type() == sys::fs::file_type::file_not_found)
+      continue;
+
+    // Create directory tree.
+    if (std::error_code EC =
+            sys::fs::create_directories(sys::path::parent_path(entry.RPath),
+                                        /*IgnoreExisting=*/true)) {
+      if (StopOnError)
+        return EC;
+    }
+
     if (Stat.type() == sys::fs::file_type::directory_file) {
       // Construct a directory when it's just a directory entry.
       if (std::error_code EC =


        


More information about the llvm-commits mailing list