LLVM  8.0.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
llvm::vfs::RedirectingFileSystem Class Reference

A virtual file system parsed from a YAML file. More...

#include "llvm/Support/VirtualFileSystem.h"

Inheritance diagram for llvm::vfs::RedirectingFileSystem:
Inheritance graph
[legend]
Collaboration diagram for llvm::vfs::RedirectingFileSystem:
Collaboration graph
[legend]

Classes

class  Entry
 A single file or directory in the VFS. More...
 
class  RedirectingDirectoryEntry
 
class  RedirectingFileEntry
 

Public Types

enum  EntryKind { EK_Directory, EK_File }
 

Public Member Functions

ErrorOr< Entry * > lookupPath (const Twine &Path) const
 Looks up Path in Roots. More...
 
ErrorOr< Statusstatus (const Twine &Path) override
 Get the status of the entry at Path, if one exists. More...
 
ErrorOr< std::unique_ptr< File > > openFileForRead (const Twine &Path) override
 Get a File object for the file at Path, if one exists. More...
 
std::error_code getRealPath (const Twine &Path, SmallVectorImpl< char > &Output) const override
 Gets real path of Path e.g. More...
 
llvm::ErrorOr< std::string > getCurrentWorkingDirectory () const override
 Get the working directory of this file system. More...
 
std::error_code setCurrentWorkingDirectory (const Twine &Path) override
 Set the working directory. More...
 
std::error_code isLocal (const Twine &Path, bool &Result) override
 Is the file mounted on a local filesystem? More...
 
directory_iterator dir_begin (const Twine &Dir, std::error_code &EC) override
 Get a directory_iterator for Dir. More...
 
void setExternalContentsPrefixDir (StringRef PrefixDir)
 
StringRef getExternalContentsPrefixDir () const
 
LLVM_DUMP_METHOD void dump () const
 
LLVM_DUMP_METHOD void dumpEntry (Entry *E, int NumSpaces=0) const
 
- Public Member Functions inherited from llvm::vfs::FileSystem
virtual ~FileSystem ()
 
llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > getBufferForFile (const Twine &Name, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
 This is a convenience method that opens a file, gets its content and then closes the file. More...
 
bool exists (const Twine &Path)
 Check whether a file exists. Provided for convenience. More...
 
std::error_code makeAbsolute (SmallVectorImpl< char > &Path) const
 Make Path an absolute path. More...
 
- Public Member Functions inherited from llvm::ThreadSafeRefCountedBase< FileSystem >
void Retain () const
 
void Release () const
 

Static Public Member Functions

static RedirectingFileSystemcreate (std::unique_ptr< MemoryBuffer > Buffer, SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, void *DiagContext, IntrusiveRefCntPtr< FileSystem > ExternalFS)
 Parses Buffer, which is expected to be in YAML format and returns a virtual file system representing its contents. More...
 

Friends

class VFSFromYamlDirIterImpl
 
class RedirectingFileSystemParser
 

Additional Inherited Members

- Protected Member Functions inherited from llvm::ThreadSafeRefCountedBase< FileSystem >
 ThreadSafeRefCountedBase ()
 

Detailed Description

A virtual file system parsed from a YAML file.

Currently, this class allows creating virtual directories and mapping virtual file paths to existing external files, available in ExternalFS.

The basic structure of the parsed file is:

/// {
///   'version': <version number>,
///   <optional configuration>
///   'roots': [
///              <directory entries>
///            ]
/// }
/// 
All configuration options are optional.
  'case-sensitive': <boolean, default=true>
  'use-external-names': <boolean, default=true>
  'overlay-relative': <boolean, default=false>
  'fallthrough': <boolean, default=true>

Virtual directories are represented as
/// {
///   'type': 'directory',
///   'name': <string>,
///   'contents': [ <file or directory entries> ]
/// }
/// 
The default attributes for virtual directories are:
/// MTime = now() when created
/// Perms = 0777
/// User = Group = 0
/// Size = 0
/// UniqueID = unspecified unique value
/// 
Re-mapped files are represented as
/// {
///   'type': 'file',
///   'name': <string>,
///   'use-external-name': <boolean> # Optional
///   'external-contents': <path to external file>
/// }
/// 
and inherit their attributes from the external contents.

In both cases, the 'name' field may contain multiple path components (e.g.
/path/to/file). However, any directory that contains more than one child
must be uniquely represented by a directory entry.  

Definition at line 557 of file VirtualFileSystem.h.

Member Enumeration Documentation

◆ EntryKind

Enumerator
EK_Directory 
EK_File 

Definition at line 559 of file VirtualFileSystem.h.

Member Function Documentation

◆ create()

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

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

Definition at line 1513 of file VirtualFileSystem.cpp.

References assert(), llvm::SourceMgr::DK_Error, llvm::StringRef::empty(), llvm::sys::fs::make_absolute(), P, llvm::sys::path::parent_path(), llvm::vfs::RedirectingFileSystemParser::parse(), llvm::SourceMgr::PrintMessage(), and llvm::SourceMgr::setDiagHandler().

Referenced by getRealPath(), and getVFSEntries().

◆ dir_begin()

directory_iterator RedirectingFileSystem::dir_begin ( const Twine Dir,
std::error_code &  EC 
)
overridevirtual

Get a directory_iterator for Dir.

Note
The 'end' iterator is directory_iterator().

Implements llvm::vfs::FileSystem.

Definition at line 1006 of file VirtualFileSystem.cpp.

References D, E, llvm::ErrorOr< T >::getError(), llvm::no_such_file_or_directory, llvm::not_a_directory, and llvm::vfs::InMemoryFileSystem::status().

◆ dump()

LLVM_DUMP_METHOD void RedirectingFileSystem::dump ( ) const

Definition at line 1041 of file VirtualFileSystem.cpp.

References LLVM_DUMP_METHOD.

◆ dumpEntry()

LLVM_DUMP_METHOD void RedirectingFileSystem::dumpEntry ( RedirectingFileSystem::Entry E,
int  NumSpaces = 0 
) const

◆ getCurrentWorkingDirectory()

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

Get the working directory of this file system.

Implements llvm::vfs::FileSystem.

Definition at line 992 of file VirtualFileSystem.cpp.

◆ getExternalContentsPrefixDir()

StringRef RedirectingFileSystem::getExternalContentsPrefixDir ( ) const

Definition at line 1036 of file VirtualFileSystem.cpp.

◆ getRealPath()

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

Gets real path of 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.

Reimplemented from llvm::vfs::FileSystem.

Definition at line 1725 of file VirtualFileSystem.cpp.

References create(), F(), llvm::ErrorOr< T >::getError(), llvm::vfs::getVFSFromYAML(), llvm::invalid_argument, and llvm::no_such_file_or_directory.

◆ isLocal()

std::error_code RedirectingFileSystem::isLocal ( const Twine Path,
bool Result 
)
overridevirtual

Is the file mounted on a local filesystem?

Reimplemented from llvm::vfs::FileSystem.

Definition at line 1001 of file VirtualFileSystem.cpp.

◆ lookupPath()

ErrorOr< RedirectingFileSystem::Entry * > RedirectingFileSystem::lookupPath ( const Twine Path) const

◆ openFileForRead()

ErrorOr< std::unique_ptr< File > > RedirectingFileSystem::openFileForRead ( const Twine Path)
overridevirtual

◆ setCurrentWorkingDirectory()

std::error_code RedirectingFileSystem::setCurrentWorkingDirectory ( const Twine Path)
overridevirtual

Set the working directory.

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

Implements llvm::vfs::FileSystem.

Definition at line 997 of file VirtualFileSystem.cpp.

◆ setExternalContentsPrefixDir()

void RedirectingFileSystem::setExternalContentsPrefixDir ( StringRef  PrefixDir)

Definition at line 1032 of file VirtualFileSystem.cpp.

References llvm::StringRef::str().

◆ status()

ErrorOr< Status > RedirectingFileSystem::status ( const Twine Path)
overridevirtual

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

Implements llvm::vfs::FileSystem.

Definition at line 1657 of file VirtualFileSystem.cpp.

References llvm::ErrorOr< T >::getError(), llvm::no_such_file_or_directory, and llvm::vfs::InMemoryFileSystem::status().

Friends And Related Function Documentation

◆ RedirectingFileSystemParser

friend class RedirectingFileSystemParser
friend

Definition at line 632 of file VirtualFileSystem.h.

◆ VFSFromYamlDirIterImpl

friend class VFSFromYamlDirIterImpl
friend

Definition at line 631 of file VirtualFileSystem.h.


The documentation for this class was generated from the following files: