LLVM 18.0.0git
|
An in-memory file system. More...
#include "llvm/Support/VirtualFileSystem.h"
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. | |
bool | addHardLink (const Twine &NewLink, const Twine &Target) |
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 |
bool | useNormalizedPaths () const |
Return true if this file system normalizes . and .. in paths. | |
llvm::ErrorOr< Status > | status (const Twine &Path) override |
Get the status of the entry at Path , if one exists. | |
llvm::ErrorOr< std::unique_ptr< File > > | openFileForRead (const Twine &Path) override |
Get a File object for the file at Path , if one exists. | |
directory_iterator | dir_begin (const Twine &Dir, std::error_code &EC) override |
Get a directory_iterator for Dir . | |
llvm::ErrorOr< std::string > | getCurrentWorkingDirectory () const override |
Get the working directory of this file system. | |
std::error_code | getRealPath (const Twine &Path, SmallVectorImpl< char > &Output) const 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 |
Is the file mounted on a local filesystem? | |
std::error_code | setCurrentWorkingDirectory (const Twine &Path) override |
Set the working directory. | |
![]() | |
virtual | ~FileSystem () |
virtual llvm::ErrorOr< Status > | status (const Twine &Path)=0 |
Get the status of the entry at Path , if one exists. | |
virtual llvm::ErrorOr< std::unique_ptr< File > > | openFileForRead (const Twine &Path)=0 |
Get a File object for the file at Path , if one exists. | |
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. | |
virtual directory_iterator | dir_begin (const Twine &Dir, std::error_code &EC)=0 |
Get a directory_iterator for Dir . | |
virtual std::error_code | setCurrentWorkingDirectory (const Twine &Path)=0 |
Set the working directory. | |
virtual llvm::ErrorOr< std::string > | getCurrentWorkingDirectory () const =0 |
Get the working directory of this file system. | |
virtual std::error_code | getRealPath (const Twine &Path, SmallVectorImpl< char > &Output) const |
Gets real path of Path e.g. | |
bool | exists (const Twine &Path) |
Check whether a file exists. Provided for convenience. | |
virtual std::error_code | isLocal (const Twine &Path, bool &Result) |
Is the file mounted on a local filesystem? | |
virtual std::error_code | makeAbsolute (SmallVectorImpl< char > &Path) const |
Make Path an absolute path. | |
void | print (raw_ostream &OS, PrintType Type=PrintType::Contents, unsigned IndentLevel=0) const |
LLVM_DUMP_METHOD void | dump () const |
![]() | |
unsigned | UseCount () const |
void | Retain () const |
void | Release () const |
Static Public Attributes | |
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 |
![]() | |
virtual void | printImpl (raw_ostream &OS, PrintType Type, unsigned IndentLevel) const |
void | printIndent (raw_ostream &OS, unsigned IndentLevel) const |
![]() | |
ThreadSafeRefCountedBase ()=default | |
ThreadSafeRefCountedBase (const ThreadSafeRefCountedBase &) | |
ThreadSafeRefCountedBase & | operator= (const ThreadSafeRefCountedBase &)=delete |
~ThreadSafeRefCountedBase () | |
Additional Inherited Members | |
![]() | |
enum class | PrintType { Summary , Contents , RecursiveContents } |
An in-memory file system.
Definition at line 501 of file VirtualFileSystem.h.
Definition at line 802 of file VirtualFileSystem.cpp.
|
overridedefault |
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.
Definition at line 893 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.
bool llvm::vfs::InMemoryFileSystem::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.
The VFS does not own the buffer. If present, User, Group, Type and Perms apply to the newly-created file or directory.
Definition at line 911 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.
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.
Definition at line 1004 of file VirtualFileSystem.cpp.
References llvm::vfs::detail::NewInMemoryNodeInfo::Path, and llvm::StringRef::str().
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 1023 of file VirtualFileSystem.cpp.
References llvm::vfs::detail::NewInMemoryNodeInfo::makeStatus(), llvm::sys::fs::symlink_file, and llvm::Twine::toVector().
|
overridevirtual |
Get a directory_iterator for Dir
.
Implements llvm::vfs::FileSystem.
Definition at line 1120 of file VirtualFileSystem.cpp.
References llvm::make_error_code(), llvm::not_a_directory, and llvm::Twine::str().
|
inlineoverridevirtual |
Get the working directory of this file system.
Implements llvm::vfs::FileSystem.
Definition at line 594 of file VirtualFileSystem.h.
Referenced by getRealPath().
|
overridevirtual |
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.
Reimplemented from llvm::vfs::FileSystem.
Definition at line 1154 of file VirtualFileSystem.cpp.
References getCurrentWorkingDirectory(), llvm::vfs::FileSystem::makeAbsolute(), llvm::operation_not_permitted, and llvm::sys::path::remove_dots().
|
overridevirtual |
Is the file mounted on a local filesystem?
Reimplemented from llvm::vfs::FileSystem.
Definition at line 1166 of file VirtualFileSystem.cpp.
|
overridevirtual |
Get a File
object for the file at Path
, if one exists.
Implements llvm::vfs::FileSystem.
Definition at line 1051 of file VirtualFileSystem.cpp.
References F, llvm::invalid_argument, and llvm::make_error_code().
|
overrideprotectedvirtual |
Reimplemented from llvm::vfs::FileSystem.
Definition at line 1171 of file VirtualFileSystem.cpp.
References OS, and llvm::vfs::FileSystem::printIndent().
|
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 1136 of file VirtualFileSystem.cpp.
References assert(), llvm::vfs::FileSystem::makeAbsolute(), P, llvm::sys::path::remove_dots(), and useNormalizedPaths().
|
overridevirtual |
Get the status of the entry at Path
, if one exists.
Implements llvm::vfs::FileSystem.
Definition at line 1043 of file VirtualFileSystem.cpp.
std::string llvm::vfs::InMemoryFileSystem::toString | ( | ) | const |
Definition at line 812 of file VirtualFileSystem.cpp.
|
inline |
Return true if this file system normalizes . and .. in paths.
Definition at line 587 of file VirtualFileSystem.h.
Referenced by setCurrentWorkingDirectory().
|
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 559 of file VirtualFileSystem.h.