class RedirectingFileSystem

Declaration

class RedirectingFileSystem : public FileSystem { /* full declaration omitted */ };

Description

A virtual file system parsed from a YAML file. Currently, this class allows creating virtual files and directories. Virtual files map to existing external files in \c ExternalFS, and virtual directories may either map to existing directories in \c ExternalFS or list their contents in the form of other virtual directories and/or files. The basic structure of the parsed file is: The roots may be absolute or relative. If relative they will be made absolute against the current working directory. All configuration options are optional. 'case-sensitive': <boolean , default=(true for Posix, false for Windows)> 'use-external-names': <boolean , default=true> 'overlay-relative': <boolean , default=false> 'fallthrough': <boolean , default=true, deprecated - use 'redirecting-with' instead> 'redirecting-with': <string , one of 'fallthrough', 'fallback', or 'redirect-only', default='fallthrough'> Virtual directories that list their contents are represented as The default attributes for such virtual directories are: When a path prefix matches such a directory, the next component in the path is matched against the entries in the 'contents' array. Re-mapped directories, on the other hand, are represented as /// and inherit their attributes from the external directory. When a path prefix matches such an entry, the unmatched components are appended to the 'external-contents' path, and the resulting path is looked up in the external file system instead. Re-mapped files are represented as Their attributes and file contents are determined by looking up the file at their 'external-contents' path in the external file system. For 'file', 'directory' and 'directory-remap' entries the 'name' field may contain multiple path components (e.g. /path/to/file). However, any directory in such a path that contains more than one child must be uniquely represented by a 'directory' entry. When the 'use-external-name' field is set, calls to \a vfs::File::status() give the external (remapped) filesystem name instead of the name the file was accessed by. This is an intentional leak through the \a RedirectingFileSystem abstraction layer. It enables clients to discover (and use) the external file location when communicating with users or tools that don't use the same VFS overlay. FIXME: 'use-external-name' causes behaviour that's inconsistent with how "real" filesystems behave. Maybe there should be a separate channel for this information.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:729

Inherits from: FileSystem

Member Variables

private std::vector<std::unique_ptr<Entry>> Roots
The root(s) of the virtual file system.
private std::string WorkingDirectory
The current working directory of the file system.
private IntrusiveRefCntPtr<llvm::vfs::FileSystem> ExternalFS
The file system to use for external references.
private std::string ExternalContentsPrefixDir
If IsRelativeOverlay is set, this represents the directory path that should be prefixed to each 'external-contents' entry when reading from YAML files.
private bool CaseSensitive = is_style_posix(sys::path::Style::native)
Currently, case-insensitive matching only works correctly with ASCII.
private bool IsRelativeOverlay = false
IsRelativeOverlay marks whether a ExternalContentsPrefixDir path must be prefixed in every 'external-contents' when reading from YAML files.
private bool UseExternalNames = true
Whether to use to use the value of 'external-contents' for the names of files. This global value is overridable on a per-file basis.
private llvm::vfs::RedirectingFileSystem::RedirectKind Redirection = RedirectKind::Fallthrough
Determines the lookups to perform, as well as their order. See\c RedirectKind for details.

Method Overview

  • private RedirectingFileSystem(IntrusiveRefCntPtr<llvm::vfs::FileSystem> ExternalFS)
  • public static std::unique_ptr<RedirectingFileSystem> create(ArrayRef<std::pair<std::string, std::string>> RemappedFiles, bool UseExternalNames, llvm::vfs::FileSystem & ExternalFS)
  • public static std::unique_ptr<RedirectingFileSystem> create(std::unique_ptr<MemoryBuffer> Buffer, SourceMgr::DiagHandlerTy DiagHandler, llvm::StringRef YAMLFilePath, void * DiagContext, IntrusiveRefCntPtr<llvm::vfs::FileSystem> ExternalFS)
  • public llvm::vfs::directory_iterator dir_begin(const llvm::Twine & Dir, std::error_code & EC)
  • public llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const
  • public llvm::StringRef getExternalContentsPrefixDir() const
  • private ErrorOr<llvm::vfs::Status> getExternalStatus(const llvm::Twine & CanonicalPath, const llvm::Twine & OriginalPath) const
  • public std::error_code getRealPath(const llvm::Twine & Path, SmallVectorImpl<char> & Output) const
  • public std::vector<llvm::StringRef> getRoots() const
  • public std::error_code isLocal(const llvm::Twine & Path, bool & Result)
  • public ErrorOr<llvm::vfs::RedirectingFileSystem::LookupResult> lookupPath(llvm::StringRef Path) const
  • private ErrorOr<llvm::vfs::RedirectingFileSystem::LookupResult> lookupPathImpl(llvm::sys::path::const_iterator Start, llvm::sys::path::const_iterator End, llvm::vfs::RedirectingFileSystem::Entry * From) const
  • public std::error_code makeAbsolute(SmallVectorImpl<char> & Path) const
  • private std::error_code makeCanonical(SmallVectorImpl<char> & Path) const
  • public ErrorOr<std::unique_ptr<File>> openFileForRead(const llvm::Twine & Path)
  • private bool pathComponentMatches(llvm::StringRef lhs, llvm::StringRef rhs) const
  • public void printEntry(llvm::raw_ostream & OS, llvm::vfs::RedirectingFileSystem::Entry * E, unsigned int IndentLevel = 0) const
  • protected void printImpl(llvm::raw_ostream & OS, llvm::vfs::FileSystem::PrintType Type, unsigned int IndentLevel) const
  • public std::error_code setCurrentWorkingDirectory(const llvm::Twine & Path)
  • public void setExternalContentsPrefixDir(llvm::StringRef PrefixDir)
  • public void setFallthrough(bool Fallthrough)
  • public void setRedirection(RedirectingFileSystem::RedirectKind Kind)
  • public ErrorOr<llvm::vfs::Status> status(const llvm::Twine & Path)
  • private ErrorOr<llvm::vfs::Status> status(const llvm::Twine & CanonicalPath, const llvm::Twine & OriginalPath, const llvm::vfs::RedirectingFileSystem::LookupResult & Result)

Inherited from FileSystem:

Methods

RedirectingFileSystem(
    IntrusiveRefCntPtr<llvm::vfs::FileSystem>
        ExternalFS)

Description

@ }

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:939

Parameters

IntrusiveRefCntPtr<llvm::vfs::FileSystem> ExternalFS

static std::unique_ptr<RedirectingFileSystem>
create(
    ArrayRef<std::pair<std::string, std::string>>
        RemappedFiles,
    bool UseExternalNames,
    llvm::vfs::FileSystem& ExternalFS)

Description

Redirect each of the remapped files from first to second.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:968

Parameters

ArrayRef<std::pair<std::string, std::string>> RemappedFiles
bool UseExternalNames
llvm::vfs::FileSystem& ExternalFS

static std::unique_ptr<RedirectingFileSystem>
create(std::unique_ptr<MemoryBuffer> Buffer,
       SourceMgr::DiagHandlerTy DiagHandler,
       llvm::StringRef YAMLFilePath,
       void* DiagContext,
       IntrusiveRefCntPtr<llvm::vfs::FileSystem>
           ExternalFS)

Description

Parses \p Buffer, which is expected to be in YAML format and returns a virtual file system representing its contents.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:962

Parameters

std::unique_ptr<MemoryBuffer> Buffer
SourceMgr::DiagHandlerTy DiagHandler
llvm::StringRef YAMLFilePath
void* DiagContext
IntrusiveRefCntPtr<llvm::vfs::FileSystem> ExternalFS

llvm::vfs::directory_iterator dir_begin(
    const llvm::Twine& Dir,
    std::error_code& EC)

Description

Get a directory_iterator for \p Dir.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:985

Parameters

const llvm::Twine& Dir
std::error_code& EC

llvm::ErrorOr<std::string>
getCurrentWorkingDirectory() const

Description

Get the working directory of this file system.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:977

llvm::StringRef getExternalContentsPrefixDir()
    const

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:989

ErrorOr<llvm::vfs::Status> getExternalStatus(
    const llvm::Twine& CanonicalPath,
    const llvm::Twine& OriginalPath) const

Description

Get the File status, or error, from the underlying external file system. This returns the status with the originally requested name, while looking up the entry using the canonical path.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:890

Parameters

const llvm::Twine& CanonicalPath
const llvm::Twine& OriginalPath

std::error_code getRealPath(
    const llvm::Twine& Path,
    SmallVectorImpl<char>& Output) const

Description

Gets real path of \p Path e.g. collapse all . and .. patterns, resolve symlinks. For real file system, this uses `llvm::sys::fs::real_path`. This returns errc::operation_not_permitted if not implemented by subclass.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:974

Parameters

const llvm::Twine& Path
SmallVectorImpl<char>& Output

std::vector<llvm::StringRef> getRoots() const

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:997

std::error_code isLocal(const llvm::Twine& Path,
                        bool& Result)

Description

Is the file mounted on a local filesystem?

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:981

Parameters

const llvm::Twine& Path
bool& Result

ErrorOr<llvm::vfs::RedirectingFileSystem::
            LookupResult>
lookupPath(llvm::StringRef Path) const

Description

Looks up \p Path in \c Roots and returns a LookupResult giving the matched entry and, if the entry was a FileEntry or DirectoryRemapEntry, the path it redirects to in the external file system.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:957

Parameters

llvm::StringRef Path

ErrorOr<llvm::vfs::RedirectingFileSystem::
            LookupResult>
lookupPathImpl(
    llvm::sys::path::const_iterator Start,
    llvm::sys::path::const_iterator End,
    llvm::vfs::RedirectingFileSystem::Entry* From)
    const

Description

Looks up the path [Start, End) in \p From, possibly recursing into the contents of \p From if it is a directory. Returns a LookupResult giving the matched entry and, if that entry is a FileEntry or DirectoryRemapEntry, the path it redirects to in the external file system.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:945

Parameters

llvm::sys::path::const_iterator Start
llvm::sys::path::const_iterator End
llvm::vfs::RedirectingFileSystem::Entry* From

std::error_code makeAbsolute(
    SmallVectorImpl<char>& Path) const

Description

Make \a Path an absolute path. Makes \a Path absolute using the current directory if it is not already. An empty \a Path will result in the current directory. /absolute/path => /absolute/path relative/../path => <current -directory>/relative/../path

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:983

Parameters

SmallVectorImpl<char>& Path
A path that is modified to be an absolute path.

Returns

success if \a path has been made absolute, otherwise a platform-specific error_code.

std::error_code makeCanonical(
    SmallVectorImpl<char>& Path) const

Description

Canonicalize path by removing ".", "..", "./", components. This is a VFS request, do not bother about symlinks in the path components but canonicalize in order to perform the correct entry search.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:885

Parameters

SmallVectorImpl<char>& Path

ErrorOr<std::unique_ptr<File>> openFileForRead(
    const llvm::Twine& Path)

Description

Get a \p File object for the file at \p Path, if one exists.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:972

Parameters

const llvm::Twine& Path

bool pathComponentMatches(
    llvm::StringRef lhs,
    llvm::StringRef rhs) const

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:898

Parameters

llvm::StringRef lhs
llvm::StringRef rhs

void printEntry(
    llvm::raw_ostream& OS,
    llvm::vfs::RedirectingFileSystem::Entry* E,
    unsigned int IndentLevel = 0) const

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:999

Parameters

llvm::raw_ostream& OS
llvm::vfs::RedirectingFileSystem::Entry* E
unsigned int IndentLevel = 0

void printImpl(
    llvm::raw_ostream& OS,
    llvm::vfs::FileSystem::PrintType Type,
    unsigned int IndentLevel) const

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:1002

Parameters

llvm::raw_ostream& OS
llvm::vfs::FileSystem::PrintType Type
unsigned int IndentLevel

std::error_code setCurrentWorkingDirectory(
    const llvm::Twine& Path)

Description

Set the working directory. This will affect all following operations on this file system and may propagate down for nested file systems.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:979

Parameters

const llvm::Twine& Path

void setExternalContentsPrefixDir(
    llvm::StringRef PrefixDir)

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:987

Parameters

llvm::StringRef PrefixDir

void setFallthrough(bool Fallthrough)

Description

Sets the redirection kind to \c Fallthrough if true or \c RedirectOnly otherwise. Will removed in the future, use \c setRedirection instead.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:993

Parameters

bool Fallthrough

void setRedirection(
    RedirectingFileSystem::RedirectKind Kind)

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:995

Parameters

RedirectingFileSystem::RedirectKind Kind

ErrorOr<llvm::vfs::Status> status(
    const llvm::Twine& Path)

Description

Get the status of the entry at \p Path, if one exists.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:971

Parameters

const llvm::Twine& Path

ErrorOr<llvm::vfs::Status> status(
    const llvm::Twine& CanonicalPath,
    const llvm::Twine& OriginalPath,
    const llvm::vfs::RedirectingFileSystem::
        LookupResult& Result)

Description

Get the status for a path with the provided \c LookupResult.

Declared at: llvm/include/llvm/Support/VirtualFileSystem.h:950

Parameters

const llvm::Twine& CanonicalPath
const llvm::Twine& OriginalPath
const llvm::vfs::RedirectingFileSystem:: LookupResult& Result