diff options
| author | Ilya Biryukov <ibiryukov@google.com> | 2018-02-13 17:08:13 +0000 |
|---|---|---|
| committer | Ilya Biryukov <ibiryukov@google.com> | 2018-02-13 17:08:13 +0000 |
| commit | 42fed626bc46599f53f496d45749755165235a7a (patch) | |
| tree | 92292cbe69942d77ad29e0abeb1a040112ce6736 /clang-tools-extra/unittests/clangd/TestFS.cpp | |
| parent | 1ce4642ddca68eb2e319ec7ad4a776b0dd960135 (diff) | |
| download | bcm5719-llvm-42fed626bc46599f53f496d45749755165235a7a.tar.gz bcm5719-llvm-42fed626bc46599f53f496d45749755165235a7a.zip | |
[clangd] Remove the RealFS layer from test VFS. NFC.
It was required before because preambles could only be created on
disk. All tests use in-memory preambles now.
llvm-svn: 325021
Diffstat (limited to 'clang-tools-extra/unittests/clangd/TestFS.cpp')
| -rw-r--r-- | clang-tools-extra/unittests/clangd/TestFS.cpp | 112 |
1 files changed, 1 insertions, 111 deletions
diff --git a/clang-tools-extra/unittests/clangd/TestFS.cpp b/clang-tools-extra/unittests/clangd/TestFS.cpp index 42fb4b87d5d..55506e6c4e0 100644 --- a/clang-tools-extra/unittests/clangd/TestFS.cpp +++ b/clang-tools-extra/unittests/clangd/TestFS.cpp @@ -12,112 +12,6 @@ namespace clang { namespace clangd { -namespace { - -/// An implementation of vfs::FileSystem that only allows access to -/// files and folders inside a set of whitelisted directories. -/// -/// FIXME(ibiryukov): should it also emulate access to parents of whitelisted -/// directories with only whitelisted contents? -class FilteredFileSystem : public vfs::FileSystem { -public: - /// The paths inside \p WhitelistedDirs should be absolute - FilteredFileSystem(std::vector<std::string> WhitelistedDirs, - IntrusiveRefCntPtr<vfs::FileSystem> InnerFS) - : WhitelistedDirs(std::move(WhitelistedDirs)), InnerFS(InnerFS) { - assert(std::all_of(WhitelistedDirs.begin(), WhitelistedDirs.end(), - [](const std::string &Path) -> bool { - return llvm::sys::path::is_absolute(Path); - }) && - "Not all WhitelistedDirs are absolute"); - } - - virtual llvm::ErrorOr<vfs::Status> status(const Twine &Path) { - if (!isInsideWhitelistedDir(Path)) - return llvm::errc::no_such_file_or_directory; - return InnerFS->status(Path); - } - - virtual llvm::ErrorOr<std::unique_ptr<vfs::File>> - openFileForRead(const Twine &Path) { - if (!isInsideWhitelistedDir(Path)) - return llvm::errc::no_such_file_or_directory; - return InnerFS->openFileForRead(Path); - } - - llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> - getBufferForFile(const Twine &Name, int64_t FileSize = -1, - bool RequiresNullTerminator = true, - bool IsVolatile = false) { - if (!isInsideWhitelistedDir(Name)) - return llvm::errc::no_such_file_or_directory; - return InnerFS->getBufferForFile(Name, FileSize, RequiresNullTerminator, - IsVolatile); - } - - virtual vfs::directory_iterator dir_begin(const Twine &Dir, - std::error_code &EC) { - if (!isInsideWhitelistedDir(Dir)) { - EC = llvm::errc::no_such_file_or_directory; - return vfs::directory_iterator(); - } - return InnerFS->dir_begin(Dir, EC); - } - - virtual std::error_code setCurrentWorkingDirectory(const Twine &Path) { - return InnerFS->setCurrentWorkingDirectory(Path); - } - - virtual llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const { - return InnerFS->getCurrentWorkingDirectory(); - } - - bool exists(const Twine &Path) { - if (!isInsideWhitelistedDir(Path)) - return false; - return InnerFS->exists(Path); - } - - std::error_code makeAbsolute(SmallVectorImpl<char> &Path) const { - return InnerFS->makeAbsolute(Path); - } - -private: - bool isInsideWhitelistedDir(const Twine &InputPath) const { - SmallString<128> Path; - InputPath.toVector(Path); - - if (makeAbsolute(Path)) - return false; - - for (const auto &Dir : WhitelistedDirs) { - if (Path.startswith(Dir)) - return true; - } - return false; - } - - std::vector<std::string> WhitelistedDirs; - IntrusiveRefCntPtr<vfs::FileSystem> InnerFS; -}; - -/// Create a vfs::FileSystem that has access only to temporary directories -/// (obtained by calling system_temp_directory). -IntrusiveRefCntPtr<vfs::FileSystem> getTempOnlyFS() { - llvm::SmallString<128> TmpDir1; - llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/false, TmpDir1); - llvm::SmallString<128> TmpDir2; - llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/true, TmpDir2); - - std::vector<std::string> TmpDirs; - TmpDirs.push_back(TmpDir1.str()); - if (TmpDir1 != TmpDir2) - TmpDirs.push_back(TmpDir2.str()); - return new FilteredFileSystem(std::move(TmpDirs), vfs::getRealFileSystem()); -} - -} // namespace - IntrusiveRefCntPtr<vfs::FileSystem> buildTestFS(llvm::StringMap<std::string> const &Files) { IntrusiveRefCntPtr<vfs::InMemoryFileSystem> MemFS( @@ -126,11 +20,7 @@ buildTestFS(llvm::StringMap<std::string> const &Files) { MemFS->addFile(FileAndContents.first(), time_t(), llvm::MemoryBuffer::getMemBuffer(FileAndContents.second, FileAndContents.first())); - - auto OverlayFS = IntrusiveRefCntPtr<vfs::OverlayFileSystem>( - new vfs::OverlayFileSystem(getTempOnlyFS())); - OverlayFS->pushOverlay(std::move(MemFS)); - return OverlayFS; + return MemFS; } Tagged<IntrusiveRefCntPtr<vfs::FileSystem>> |

