Skip to content

Commit

Permalink
[llvm] Don't create the directory hierarchy in the FileCollector...
Browse files Browse the repository at this point in the history
... 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.
  • Loading branch information
JDevlieghere committed Aug 17, 2020
1 parent 5ca7c63 commit 295eb54
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions llvm/lib/Support/FileCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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 =
Expand Down

0 comments on commit 295eb54

Please sign in to comment.