9#ifndef LLDB_HOST_FILESYSTEM_H
10#define LLDB_HOST_FILESYSTEM_H
19#include "llvm/Support/Chrono.h"
20#include "llvm/Support/VirtualFileSystem.h"
36 :
m_fs(
llvm::vfs::getRealFileSystem()),
38 FileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fs)
39 :
m_fs(std::move(fs)),
41 FileSystem(std::unique_ptr<TildeExpressionResolver> tilde_resolver)
42 :
m_fs(
llvm::vfs::getRealFileSystem()),
62 FILE *
Fopen(
const char *path,
const char *mode);
65 int Open(
const char *path,
int flags,
int mode = 0600);
67 llvm::Expected<std::unique_ptr<File>>
69 uint32_t permissions = lldb::eFilePermissionsFileDefault,
70 bool should_close_fd =
true);
76 llvm::vfs::directory_iterator
DirBegin(
const llvm::Twine &dir,
83 llvm::ErrorOr<llvm::vfs::Status>
GetStatus(
const llvm::Twine &path)
const;
112 bool Exists(
const llvm::Twine &path)
const;
157 uint64_t offset = 0);
160 uint64_t offset = 0);
161 std::shared_ptr<WritableDataBuffer>
163 uint64_t offset = 0);
164 std::shared_ptr<WritableDataBuffer>
166 uint64_t offset = 0);
187 void *baton, llvm::sys::fs::file_type file_type, llvm::StringRef);
190 llvm::sys::fs::file_type file_type, llvm::StringRef)>
194 bool find_files,
bool find_other,
196 void *callback_baton);
198 std::error_code
GetRealPath(
const llvm::Twine &path,
209 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
m_fs;
FileSystem & operator=(const FileSystem &fs)=delete
FileSystem(llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > fs)
uint64_t GetByteSize(const FileSpec &file_spec) const
Returns the on-disk size of the given file in bytes.
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
llvm::ErrorOr< llvm::vfs::Status > GetStatus(const llvm::Twine &path) const
bool GetHomeDirectory(llvm::SmallVectorImpl< char > &path) const
Get the user home directory.
static const char * PATH_CONVERSION_ERROR
static const char * DEV_NULL
bool IsLocal(const llvm::Twine &path) const
void EnumerateDirectory(llvm::Twine path, bool find_directories, bool find_files, bool find_other, EnumerateDirectoryCallbackType callback, void *callback_baton)
@ eEnumerateDirectoryResultEnter
Recurse into the current entry if it is a directory or symlink, or next if not.
@ eEnumerateDirectoryResultNext
Enumerate next entry in the current directory.
@ eEnumerateDirectoryResultQuit
Stop directory enumerations at any level.
uint64_t GetByteSize(const llvm::Twine &path) const
uint32_t GetPermissions(const llvm::Twine &path) const
bool Exists(const llvm::Twine &path) const
llvm::sys::TimePoint GetModificationTime(const FileSpec &file_spec) const
Returns the modification time of the given file.
EnumerateDirectoryResult(* EnumerateDirectoryCallbackType)(void *baton, llvm::sys::fs::file_type file_type, llvm::StringRef)
Status Symlink(const FileSpec &src, const FileSpec &dst)
bool IsDirectory(const llvm::Twine &path) const
Status ResolveSymbolicLink(const FileSpec &src, FileSpec &dst)
std::string m_home_directory
bool ResolveExecutableLocation(FileSpec &file_spec)
Call into the Host to see if it can help find the file.
bool Exists(const FileSpec &file_spec) const
Returns whether the given file exists.
bool Readable(const llvm::Twine &path) const
int Open(const char *path, int flags, int mode=0600)
Wraps ::open in a platform-independent way.
std::error_code GetRealPath(const llvm::Twine &path, llvm::SmallVectorImpl< char > &output) const
void SetHomeDirectory(std::string home_directory)
Status Readlink(const FileSpec &src, FileSpec &dst)
static std::optional< FileSystem > & InstanceImpl()
std::unique_ptr< TildeExpressionResolver > m_tilde_resolver
uint32_t GetPermissions(const FileSpec &file_spec) const
Return the current permissions of the given file.
FileSystem(const FileSystem &fs)=delete
static void Initialize(T &&...t)
uint32_t GetPermissions(const llvm::Twine &path, std::error_code &ec) const
llvm::sys::TimePoint GetModificationTime(const llvm::Twine &path) const
FileSystem(std::unique_ptr< TildeExpressionResolver > tilde_resolver)
llvm::vfs::directory_iterator DirBegin(const FileSpec &file_spec, std::error_code &ec)
Get a directory iterator.
std::error_code MakeAbsolute(llvm::SmallVectorImpl< char > &path) const
Make the given file path absolute.
llvm::ErrorOr< llvm::vfs::Status > GetStatus(const FileSpec &file_spec) const
Returns the Status object for the given file.
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > GetVirtualFileSystem()
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > m_fs
llvm::vfs::directory_iterator DirBegin(const llvm::Twine &dir, std::error_code &ec)
std::shared_ptr< WritableDataBuffer > CreateWritableDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
bool Readable(const FileSpec &file_spec) const
Returns whether the given file is readable.
bool IsDirectory(const FileSpec &file_spec) const
Returns whether the given path is a directory.
static FileSystem & Instance()
std::function< EnumerateDirectoryResult(llvm::sys::fs::file_type file_type, llvm::StringRef)> DirectoryCallback
Status RemoveFile(const FileSpec &file_spec)
Remove a single file.
FILE * Fopen(const char *path, const char *mode)
Wraps ::fopen in a platform-independent way.
bool IsLocal(const FileSpec &file_spec) const
Returns whether the given path is local to the file system.
std::shared_ptr< DataBuffer > CreateDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
Create memory buffer from path.
A class that represents a running process on the host machine.