diff --git a/llvm/include/llvm/Support/FileCollector.h b/llvm/include/llvm/Support/FileCollector.h --- a/llvm/include/llvm/Support/FileCollector.h +++ b/llvm/include/llvm/Support/FileCollector.h @@ -23,6 +23,7 @@ /// the VFS. class FileCollector { public: + /// \p Root directory gets created in copyFiles unless it already exists. FileCollector(std::string Root, std::string OverlayRoot); void addFile(const Twine &file); diff --git a/llvm/lib/Support/FileCollector.cpp b/llvm/lib/Support/FileCollector.cpp --- a/llvm/lib/Support/FileCollector.cpp +++ b/llvm/lib/Support/FileCollector.cpp @@ -34,7 +34,6 @@ FileCollector::FileCollector(std::string Root, std::string OverlayRoot) : Root(std::move(Root)), OverlayRoot(std::move(OverlayRoot)) { - sys::fs::create_directories(this->Root, true); } bool FileCollector::getRealPath(StringRef SrcPath, @@ -150,6 +149,11 @@ } std::error_code FileCollector::copyFiles(bool StopOnError) { + auto Err = sys::fs::create_directories(Root, /*IgnoreExisting=*/true); + if (Err) { + return Err; + } + std::lock_guard lock(Mutex); for (auto &entry : VFSWriter.getMappings()) {