13#include "llvm/Support/Errc.h" 
   14#include "llvm/Support/Errno.h" 
   15#include "llvm/Support/Error.h" 
   16#include "llvm/Support/FileSystem.h" 
   17#include "llvm/Support/Path.h" 
   18#include "llvm/Support/Program.h" 
   19#include "llvm/Support/Threading.h" 
   54  static std::optional<FileSystem> g_fs;
 
 
   59                                             std::error_code &ec) {
 
   61    ec = std::error_code(
static_cast<int>(errc::no_such_file_or_directory),
 
   62                         std::system_category());
 
 
   69                                             std::error_code &ec) {
 
   70  return m_fs->dir_begin(dir, ec);
 
   73llvm::ErrorOr<vfs::Status>
 
   76    return std::error_code(
static_cast<int>(errc::no_such_file_or_directory),
 
   77                           std::system_category());
 
 
   82  return m_fs->status(path);
 
   88    return sys::TimePoint<>();
 
 
   93  ErrorOr<vfs::Status> status = 
m_fs->status(path);
 
   95    return sys::TimePoint<>();
 
   96  return status->getLastModificationTime();
 
  106  ErrorOr<vfs::Status> status = 
m_fs->status(path);
 
  109  return status->getSize();
 
  117                                    std::error_code &ec)
 const {
 
  119    return sys::fs::perms::perms_not_known;
 
 
  129                                    std::error_code &ec)
 const {
 
  130  ErrorOr<vfs::Status> status = 
m_fs->status(path);
 
  132    ec = status.getError();
 
  133    return sys::fs::perms::perms_not_known;
 
  135  return status->getPermissions();
 
  153  ErrorOr<vfs::Status> status = 
m_fs->status(path);
 
  156  return status->isDirectory();
 
  165  m_fs->isLocal(path, b);
 
  174                                    bool find_files, 
bool find_other,
 
  176                                    void *callback_baton) {
 
  178  vfs::recursive_directory_iterator Iter(*
m_fs, path, EC);
 
  179  vfs::recursive_directory_iterator End;
 
  180  for (; Iter != End && !EC; Iter.increment(EC)) {
 
  181    const auto &Item = *Iter;
 
  182    ErrorOr<vfs::Status> 
Status = 
m_fs->status(Item.path());
 
  185    if (!find_files && 
Status->isRegularFile())
 
  187    if (!find_directories && 
Status->isDirectory())
 
  189    if (!find_other && 
Status->isOther())
 
  192    auto Result = callback(callback_baton, 
Status->getType(), Item.path());
 
 
  204  return m_fs->makeAbsolute(path);
 
 
  208  SmallString<128> path;
 
  209  file_spec.
GetPath(path, 
false);
 
  216  file_spec = new_file_spec;
 
 
  222  return m_fs->getRealPath(path, output);
 
 
  230  SmallString<128> resolved(path.begin(), path.end());
 
  231  assert(
m_tilde_resolver && 
"must initialize tilde resolver in constructor");
 
  232  m_tilde_resolver->ResolveFullPath(llvm::StringRef(path.begin(), path.size()),
 
  236  SmallString<128> absolute(resolved.begin(), resolved.end());
 
  241    path.append(absolute.begin(), absolute.end());
 
  243    path.append(resolved.begin(), resolved.end());
 
 
  252  SmallString<128> path;
 
 
  267                                          uint64_t size, uint64_t offset,
 
  269  std::unique_ptr<T> buffer;
 
  271    auto buffer_or_error = T::getFile(path, is_volatile);
 
  272    if (!buffer_or_error)
 
  274    buffer = std::move(*buffer_or_error);
 
  276    auto buffer_or_error = T::getFileSlice(path, size, offset, is_volatile);
 
  277    if (!buffer_or_error)
 
  279    buffer = std::move(*buffer_or_error);
 
 
  284std::shared_ptr<WritableDataBuffer>
 
  287  const bool is_volatile = !
IsLocal(path);
 
  292  return std::make_shared<WritableDataBufferLLVM>(std::move(buffer));
 
 
  295std::shared_ptr<DataBuffer>
 
  298  const bool is_volatile = !
IsLocal(path);
 
  303  return std::make_shared<DataBufferLLVM>(std::move(buffer));
 
 
  306std::shared_ptr<WritableDataBuffer>
 
  312std::shared_ptr<DataBuffer>
 
  330  const std::string filename_str(filename.
GetCString());
 
  331  llvm::ErrorOr<std::string> error_or_path =
 
  332      llvm::sys::findProgramByName(filename_str);
 
  337  llvm::StringRef path = *error_or_path;
 
  338  llvm::StringRef parent = llvm::sys::path::parent_path(path);
 
  339  if (parent.empty() || parent == 
".")
 
 
  356  return llvm::sys::path::home_directory(path);
 
 
  360  SmallString<128> home_dir;
 
 
  369  return const_cast<FileSystem &
>(fs).Open(path, flags, mode);
 
 
  379      open_flags |= O_RDWR;
 
  381      open_flags |= O_WRONLY;
 
  384      open_flags |= O_APPEND;
 
  387      open_flags |= O_TRUNC;
 
  390      open_flags |= O_CREAT;
 
  393      open_flags |= O_CREAT | O_EXCL;
 
  395    open_flags |= O_RDONLY;
 
  399      open_flags |= O_NOFOLLOW;
 
  407    open_flags |= O_CLOEXEC;
 
  409  open_flags |= O_BINARY;
 
 
  417  if (permissions & lldb::eFilePermissionsUserRead)
 
  419  if (permissions & lldb::eFilePermissionsUserWrite)
 
  421  if (permissions & lldb::eFilePermissionsUserExecute)
 
  423  if (permissions & lldb::eFilePermissionsGroupRead)
 
  425  if (permissions & lldb::eFilePermissionsGroupWrite)
 
  427  if (permissions & lldb::eFilePermissionsGroupExecute)
 
  429  if (permissions & lldb::eFilePermissionsWorldRead)
 
  431  if (permissions & lldb::eFilePermissionsWorldWrite)
 
  433  if (permissions & lldb::eFilePermissionsWorldExecute)
 
 
  440                                  uint32_t permissions, 
bool should_close_fd) {
 
  442  const mode_t open_mode =
 
  443      (open_flags & O_CREAT) ? 
GetOpenMode(permissions) : 0;
 
  445  auto path = file_spec.
GetPath();
 
  447  int descriptor = llvm::sys::RetryAfterSignal(
 
  448      -1, 
OpenWithFS, *
this, path.c_str(), open_flags, open_mode);
 
  451    return llvm::errorCodeToError(
 
  452        std::error_code(errno, std::system_category()));
 
  454  auto file = std::unique_ptr<File>(
 
  455      new NativeFile(descriptor, options, should_close_fd));
 
  456  assert(file->IsValid());
 
  457  return std::move(file);
 
 
  469  return Status(llvm::sys::fs::remove(path));
 
 
A uniqued constant string class.
bool IsEmpty() const
Test for empty string.
const char * GetCString() const
Get the string value as a C string.
void SetDirectory(ConstString directory)
Directory string set accessor.
const ConstString & GetFilename() const
Filename string const get accessor.
const ConstString & GetDirectory() const
Directory string const get accessor.
void SetPath(llvm::StringRef p)
Temporary helper for FileSystem change.
Style GetPathStyle() const
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
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.
bool GetHomeDirectory(llvm::SmallVectorImpl< char > &path) const
Get the user home directory.
void EnumerateDirectory(llvm::Twine path, bool find_directories, bool find_files, bool find_other, EnumerateDirectoryCallbackType callback, void *callback_baton)
@ eEnumerateDirectoryResultNext
Enumerate next entry in the current directory.
@ eEnumerateDirectoryResultQuit
Stop directory enumerations at any level.
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)
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.
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)
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.
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 > m_fs
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()
Status RemoveFile(const FileSpec &file_spec)
Remove a single file.
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.
static bool DescriptorIsValid(int descriptor)
@ eOpenOptionCanCreateNewOnly
@ eOpenOptionDontFollowSymlinks
static int GetOpenFlags(File::OpenOptions options)
static mode_t GetOpenMode(uint32_t permissions)
static std::unique_ptr< T > GetMemoryBuffer(const llvm::Twine &path, uint64_t size, uint64_t offset, bool is_volatile)
static int OpenWithFS(const FileSystem &fs, const char *path, int flags, int mode)
A class that represents a running process on the host machine.