LLVM 22.0.0git
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
llvm::vfs::InMemoryFileSystem Class Reference

An in-memory file system. More...

#include "llvm/Support/VirtualFileSystem.h"

Inheritance diagram for llvm::vfs::InMemoryFileSystem:
[フレーム]
[legend]

Classes

class   DirIterator
  Adaptor from InMemoryDir::iterator to directory_iterator. More...

Public Member Functions

  InMemoryFileSystem (bool UseNormalizedPaths=true)
  ~InMemoryFileSystem () override
bool  addFile (const Twine &Path, time_t ModificationTime, std::unique_ptr< llvm::MemoryBuffer > Buffer, std::optional< uint32_t > User=std::nullopt, std::optional< uint32_t > Group=std::nullopt, std::optional< llvm::sys::fs::file_type > Type=std::nullopt, std::optional< llvm::sys::fs::perms > Perms=std::nullopt)
  Add a file containing a buffer or a directory to the VFS with a path.
  Add a hard link to a file.
bool  addSymbolicLink (const Twine &NewLink, const Twine &Target, time_t ModificationTime, std::optional< uint32_t > User=std::nullopt, std::optional< uint32_t > Group=std::nullopt, std::optional< llvm::sys::fs::perms > Perms=std::nullopt)
  Add a symbolic link.
bool  addFileNoOwn (const Twine &Path, time_t ModificationTime, const llvm::MemoryBufferRef &Buffer, std::optional< uint32_t > User=std::nullopt, std::optional< uint32_t > Group=std::nullopt, std::optional< llvm::sys::fs::file_type > Type=std::nullopt, std::optional< llvm::sys::fs::perms > Perms=std::nullopt)
  Add a buffer to the VFS with a path.
std::string  toString () const
  Return true if this file system normalizes . and .. in paths.
llvm::ErrorOr< Statusstatus (const Twine &Path) override
llvm::ErrorOr< std::unique_ptr< File > >  openFileForRead (const Twine &Path) override
directory_iterator  dir_begin (const Twine &Dir, std::error_code &EC) override
llvm::ErrorOr< std::string >  getCurrentWorkingDirectory () const override
std::error_code  getRealPath (const Twine &Path, SmallVectorImpl< char > &Output) override
  Canonicalizes Path by combining with the current working directory and normalizing the path (e.g.
std::error_code  isLocal (const Twine &Path, bool &Result) override
std::error_code  setCurrentWorkingDirectory (const Twine &Path) override
Public Member Functions inherited from llvm::RTTIExtends< InMemoryFileSystem, FileSystem >
const void *  dynamicClassID () const override
bool  isA () const
  Check whether this instance is a subclass of QueryT.

Static Public Attributes

static const char  ID = 0
static constexpr size_t  MaxSymlinkDepth = 16
  Arbitrary max depth to search through symlinks.

Protected Member Functions

void  printImpl (raw_ostream &OS, PrintType Type, unsigned IndentLevel) const override

Additional Inherited Members

Static Public Member Functions inherited from llvm::RTTIExtends< InMemoryFileSystem, FileSystem >
static const void *  classID ()
static bool  classof (const T *R)

Detailed Description

An in-memory file system.

Definition at line 541 of file VirtualFileSystem.h.

Constructor & Destructor Documentation

◆  InMemoryFileSystem()

llvm::vfs::InMemoryFileSystem::InMemoryFileSystem ( bool UseNormalizedPaths = true )
explicit

Definition at line 839 of file VirtualFileSystem.cpp.

References llvm::vfs::getDirectoryID().

Referenced by llvm::vfs::InMemoryFileSystem::DirIterator::DirIterator().

◆  ~InMemoryFileSystem()

llvm::vfs::InMemoryFileSystem::~InMemoryFileSystem ( )
overridedefault

References addHardLink().

Member Function Documentation

◆  addFile()

bool llvm::vfs::InMemoryFileSystem::addFile ( const Twine & Path,
time_t ModificationTime,
std::unique_ptr< llvm::MemoryBuffer > Buffer,
std::optional< uint32_t > User = std::nullopt,
std::optional< uint32_t > Group = std::nullopt,
std::optional< llvm::sys::fs::file_type > Type = std::nullopt,
std::optional< llvm::sys::fs::perms > Perms = std::nullopt )

Add a file containing a buffer or a directory to the VFS with a path.

The VFS owns the buffer. If present, User, Group, Type and Perms apply to the newly-created file or directory.

Returns
true if the file or directory was successfully added, false if the file or directory already exists in the file system with different contents.

Definition at line 931 of file VirtualFileSystem.cpp.

References llvm::vfs::detail::NewInMemoryNodeInfo::Buffer, llvm::sys::fs::directory_file, llvm::vfs::Status::getType(), llvm::vfs::detail::NewInMemoryNodeInfo::makeStatus(), and P.

◆  addFileNoOwn()

bool llvm::vfs::InMemoryFileSystem::addFileNoOwn ( const Twine & Path,
time_t ModificationTime,
std::optional< uint32_t > User = std::nullopt,
std::optional< uint32_t > Group = std::nullopt,
std::optional< llvm::sys::fs::file_type > Type = std::nullopt,
std::optional< llvm::sys::fs::perms > Perms = std::nullopt )

Add a buffer to the VFS with a path.

The VFS does not own the buffer. If present, User, Group, Type and Perms apply to the newly-created file or directory.

Returns
true if the file or directory was successfully added, false if the file or directory already exists in the file system with different contents.

Definition at line 949 of file VirtualFileSystem.cpp.

References llvm::vfs::detail::NewInMemoryNodeInfo::Buffer, llvm::sys::fs::directory_file, llvm::MemoryBuffer::getMemBuffer(), llvm::vfs::Status::getType(), llvm::vfs::detail::NewInMemoryNodeInfo::makeStatus(), and P.

◆  addHardLink()

bool llvm::vfs::InMemoryFileSystem::addHardLink ( const Twine & NewLink,
const Twine & Target )

Add a hard link to a file.

Here hard links are not intended to be fully equivalent to the classical filesystem. Both the hard link and the file share the same buffer and status (and thus have the same UniqueID). Because of this there is no way to distinguish between the link and the file after the link has been added.

The Target path must be an existing file or a hardlink. The NewLink file must not have been added before. The Target path must not be a directory. The NewLink node is added as a hard link which points to the resolved file of Target node.

Returns
true if the above condition is satisfied and hardlink was successfully created, false otherwise.

Definition at line 1042 of file VirtualFileSystem.cpp.

References llvm::cast(), llvm::isa(), llvm::vfs::detail::NewInMemoryNodeInfo::Path, and llvm::StringRef::str().

Referenced by ~InMemoryFileSystem().

◆  addSymbolicLink()

bool llvm::vfs::InMemoryFileSystem::addSymbolicLink ( const Twine & NewLink,
const Twine & Target,
time_t ModificationTime,
std::optional< uint32_t > User = std::nullopt,
std::optional< uint32_t > Group = std::nullopt,
std::optional< llvm::sys::fs::perms > Perms = std::nullopt )

Add a symbolic link.

Unlike a HardLink, because Target doesn't need to refer to a file (or refer to anything, as it happens). Also, an in-memory directory for Target isn't automatically created.

Definition at line 1061 of file VirtualFileSystem.cpp.

References llvm::vfs::detail::NewInMemoryNodeInfo::makeStatus(), llvm::sys::fs::symlink_file, and llvm::Twine::toVector().

◆  dir_begin()

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

Definition at line 1158 of file VirtualFileSystem.cpp.

References llvm::dyn_cast(), llvm::vfs::make_error_code(), llvm::not_a_directory, and llvm::Twine::str().

◆  getCurrentWorkingDirectory()

llvm::ErrorOr< std::string > llvm::vfs::InMemoryFileSystem::getCurrentWorkingDirectory ( ) const
inlineoverride

Definition at line 639 of file VirtualFileSystem.h.

Referenced by getRealPath().

◆  getRealPath()

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

Canonicalizes Path by combining with the current working directory and normalizing the path (e.g.

remove dots). If the current working directory is not set, this returns errc::operation_not_permitted.

This doesn't resolve symlinks as they are not supported in in-memory file system.

Definition at line 1191 of file VirtualFileSystem.cpp.

References getCurrentWorkingDirectory(), makeAbsolute(), llvm::operation_not_permitted, and llvm::sys::path::remove_dots().

◆  isLocal()

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

Definition at line 1203 of file VirtualFileSystem.cpp.

◆  openFileForRead()

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

Definition at line 1089 of file VirtualFileSystem.cpp.

References llvm::dyn_cast(), F, llvm::invalid_argument, and llvm::vfs::make_error_code().

◆  printImpl()

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

Definition at line 1208 of file VirtualFileSystem.cpp.

◆  setCurrentWorkingDirectory()

std::error_code llvm::vfs::InMemoryFileSystem::setCurrentWorkingDirectory ( const Twine & Path )
override

Definition at line 1174 of file VirtualFileSystem.cpp.

References assert(), makeAbsolute(), P, llvm::sys::path::remove_dots(), and useNormalizedPaths().

◆  status()

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

Definition at line 1081 of file VirtualFileSystem.cpp.

◆  toString()

std::string llvm::vfs::InMemoryFileSystem::toString ( ) const

Definition at line 849 of file VirtualFileSystem.cpp.

◆  useNormalizedPaths()

bool llvm::vfs::InMemoryFileSystem::useNormalizedPaths ( ) const
inline

Return true if this file system normalizes . and .. in paths.

Definition at line 632 of file VirtualFileSystem.h.

Referenced by setCurrentWorkingDirectory().

Member Data Documentation

◆  ID

const char InMemoryFileSystem::ID = 0
static

Definition at line 548 of file VirtualFileSystem.h.

◆  MaxSymlinkDepth

size_t llvm::vfs::InMemoryFileSystem::MaxSymlinkDepth = 16
staticconstexpr

Arbitrary max depth to search through symlinks.

We can get into problems if a link links to a link that links back to the link, for example.

Definition at line 604 of file VirtualFileSystem.h.


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

Generated on for LLVM by doxygen 1.14.0

AltStyle によって変換されたページ (->オリジナル) /