From 4c53f4202a45266ac89ae240c05e2bdcbfc3308f Mon Sep 17 00:00:00 2001 From: Jan Korous Date: Wed, 29 Apr 2020 11:44:40 -0700 Subject: [PATCH] [FileCollector] move Root creation If we don't handle the errors we can't rely on the directory being created early anyway. Differential Revision: https://reviews.llvm.org/D78959 --- llvm/include/llvm/Support/FileCollector.h | 1 + llvm/lib/Support/FileCollector.cpp | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/Support/FileCollector.h b/llvm/include/llvm/Support/FileCollector.h index 3a8741c..30e3470 100644 --- a/llvm/include/llvm/Support/FileCollector.h +++ b/llvm/include/llvm/Support/FileCollector.h @@ -23,6 +23,7 @@ class FileCollectorFileSystem; /// 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 index e13a7b5..cb83d84 100644 --- a/llvm/lib/Support/FileCollector.cpp +++ b/llvm/lib/Support/FileCollector.cpp @@ -34,7 +34,6 @@ static bool isCaseSensitivePath(StringRef Path) { 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 @@ copyAccessAndModificationTime(StringRef Filename, } 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()) { -- 2.7.4