summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/FileCollector.cpp
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2019-07-25 21:47:11 +0000
committerAlex Lorenz <arphaman@gmail.com>2019-07-25 21:47:11 +0000
commitb680422ef809942767cb0bfec4f00af197c3d2c4 (patch)
treec15e73df95b01fa4e50f2e928b665edb59dd7d89 /llvm/lib/Support/FileCollector.cpp
parente54dc6b8b58d7b94c2737adb941c25fea54b6a70 (diff)
downloadbcm5719-llvm-b680422ef809942767cb0bfec4f00af197c3d2c4.tar.gz
bcm5719-llvm-b680422ef809942767cb0bfec4f00af197c3d2c4.zip
[FileCollector] add support for recording empty directories
The file collector class is useful for constructing reproducers by creating a snapshot of the files that are accessed. Sometimes it might also be important to construct directories that don't necessarily have files, but are still accessed by some tool that we want to make a reproducer for. This is useful for instance for modeling the behavior of Clang's header search, which scans through a number of directories it doesn't actually access when looking for framework headers. This commit extends the file collector to allow it to work with paths that are just directories, by constructing them as the files are copied over. Differential Revision: https://reviews.llvm.org/D65297 llvm-svn: 367061
Diffstat (limited to 'llvm/lib/Support/FileCollector.cpp')
-rw-r--r--llvm/lib/Support/FileCollector.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/llvm/lib/Support/FileCollector.cpp b/llvm/lib/Support/FileCollector.cpp
index b0e67ec0d65..7e14282af08 100644
--- a/llvm/lib/Support/FileCollector.cpp
+++ b/llvm/lib/Support/FileCollector.cpp
@@ -132,6 +132,25 @@ std::error_code FileCollector::copyFiles(bool 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)) {
+ if (StopOnError)
+ return EC;
+ continue;
+ }
+
+ if (Stat.type() == sys::fs::file_type::directory_file) {
+ // Construct a directory when it's just a directory entry.
+ if (std::error_code EC =
+ sys::fs::create_directories(entry.RPath,
+ /*IgnoreExisting=*/true)) {
+ if (StopOnError)
+ return EC;
+ }
+ continue;
+ }
+
// Copy file over.
if (std::error_code EC = sys::fs::copy_file(entry.VPath, entry.RPath)) {
if (StopOnError)
@@ -147,12 +166,6 @@ std::error_code FileCollector::copyFiles(bool StopOnError) {
}
// Copy over modification time.
- sys::fs::file_status Stat;
- if (std::error_code EC = sys::fs::status(entry.VPath, Stat)) {
- if (StopOnError)
- return EC;
- continue;
- }
copyAccessAndModificationTime(entry.RPath, Stat);
}
return {};
OpenPOWER on IntegriCloud