From 87ba87bc4d200f64bbf56673f3a6f01c13943d1f Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Wed, 19 Feb 2014 03:29:17 +0000 Subject: Add an OverlayFileSystem class Provides a way to merge multiple vfs::FileSystem objects into a single filesystem. llvm-svn: 201635 --- clang/lib/Basic/VirtualFileSystem.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'clang/lib/Basic/VirtualFileSystem.cpp') diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp index 0345ed153e3..7afdac864b9 100644 --- a/clang/lib/Basic/VirtualFileSystem.cpp +++ b/clang/lib/Basic/VirtualFileSystem.cpp @@ -160,3 +160,36 @@ IntrusiveRefCntPtr vfs::getRealFileSystem() { static IntrusiveRefCntPtr FS = new RealFileSystem(); return FS; } + +//===-----------------------------------------------------------------------===/ +// OverlayFileSystem implementation +//===-----------------------------------------------------------------------===/ +OverlayFileSystem::OverlayFileSystem( + IntrusiveRefCntPtr BaseFS) { + pushOverlay(BaseFS); +} + +void OverlayFileSystem::pushOverlay(IntrusiveRefCntPtr FS) { + FSList.push_back(FS); +} + +ErrorOr OverlayFileSystem::status(const Twine &Path) { + // FIXME: handle symlinks that cross file systems + for (iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) { + ErrorOr Status = (*I)->status(Path); + if (Status || Status.getError() != errc::no_such_file_or_directory) + return Status; + } + return error_code(errc::no_such_file_or_directory, system_category()); +} + +error_code OverlayFileSystem::openFileForRead(const llvm::Twine &Path, + OwningPtr &Result) { + // FIXME: handle symlinks that cross file systems + for (iterator I = overlays_begin(), E = overlays_end(); I != E; ++I) { + error_code EC = (*I)->openFileForRead(Path, Result); + if (!EC || EC != errc::no_such_file_or_directory) + return EC; + } + return error_code(errc::no_such_file_or_directory, system_category()); +} -- cgit v1.2.3