27 #ifndef LLVM_SUPPORT_FILESYSTEM_H
28 #define LLVM_SUPPORT_FILESYSTEM_H
43 #include <system_error>
47 #ifdef HAVE_SYS_STAT_H
103 return static_cast<perms>(
static_cast<unsigned short>(l) |
104 static_cast<unsigned short>(r));
107 return static_cast<perms>(
static_cast<unsigned short>(l) &
108 static_cast<unsigned short>(r));
120 return static_cast<perms>(
121 static_cast<unsigned short>(~static_cast<
unsigned short>(x)));
130 UniqueID(uint64_t Device, uint64_t File) : Device(Device), File(File) {}
133 return Device == Other.Device && File == Other.File;
137 return std::tie(Device, File) < std::tie(Other.Device, Other.File);
150 #if defined(LLVM_ON_UNIX)
152 nlink_t fs_st_nlinks = 0;
154 time_t fs_st_atime = 0;
155 time_t fs_st_mtime = 0;
158 off_t fs_st_size = 0;
159 #elif defined (LLVM_ON_WIN32)
175 #if defined(LLVM_ON_UNIX)
181 time_t ATime, time_t MTime, uid_t UID, gid_t GID, off_t
Size)
182 : fs_st_dev(Dev), fs_st_nlinks(Links), fs_st_ino(Ino), fs_st_atime(ATime),
183 fs_st_mtime(MTime), fs_st_uid(UID), fs_st_gid(GID), fs_st_size(Size),
184 Type(Type), Perms(Perms) {}
185 #elif defined(LLVM_ON_WIN32)
196 : NumLinks(LinkCount), LastAccessedTimeHigh(LastAccessTimeHigh),
197 LastAccessedTimeLow(LastAccessTimeLow),
198 LastWriteTimeHigh(LastWriteTimeHigh),
199 LastWriteTimeLow(LastWriteTimeLow),
200 VolumeSerialNumber(VolumeSerialNumber), FileSizeHigh(FileSizeHigh),
201 FileSizeLow(FileSizeLow), FileIndexHigh(FileIndexHigh),
202 FileIndexLow(FileIndexLow), Type(Type), Perms(Perms) {}
213 #if defined(LLVM_ON_UNIX)
214 uint32_t getUser()
const {
return fs_st_uid; }
215 uint32_t getGroup()
const {
return fs_st_gid; }
216 uint64_t getSize()
const {
return fs_st_size; }
217 #elif defined (LLVM_ON_WIN32)
226 uint64_t getSize()
const {
227 return (uint64_t(FileSizeHigh) << 32) + FileSizeLow;
274 bool IgnoreExisting =
true,
315 bool expand_tilde =
false);
337 std::error_code
remove(
const Twine &path,
bool IgnoreNonExisting =
true);
364 std::error_code
resize_file(
int FD, uint64_t Size);
427 bool equivalent(file_status A, file_status B);
458 std::error_code
is_local(
int FD,
bool &result);
464 return !
is_local(Path, Result) && Result;
471 return !
is_local(FD, Result) && Result;
577 std::error_code
status(
const Twine &path, file_status &result,
581 std::error_code
status(
int FD, file_status &Result);
612 std::error_code EC =
status(Path, Status);
615 Result = Status.getSize();
616 return std::error_code();
715 return OpenFlags(
unsigned(A) |
unsigned(B));
768 std::error_code &ec);
772 uint64_t
size()
const;
803 : Path(path.str()), FollowSymlinks(follow_symlinks), Status(st) {}
814 const std::string &
path()
const {
return Path; }
849 std::shared_ptr<detail::DirIterState> State;
850 bool FollowSymlinks =
true;
854 bool follow_symlinks =
true)
855 : FollowSymlinks(follow_symlinks) {
856 State = std::make_shared<detail::DirIterState>();
859 *State, path.
toStringRef(path_storage), FollowSymlinks);
863 bool follow_symlinks =
true)
864 : FollowSymlinks(follow_symlinks) {
865 State = std::make_shared<detail::DirIterState>();
883 if (State == RHS.State)
889 return State->CurrentEntry == RHS.State->CurrentEntry;
893 return !(*
this == RHS);
903 std::stack<directory_iterator, std::vector<directory_iterator>>
Stack;
913 std::shared_ptr<detail::RecDirIterState> State;
919 bool follow_symlinks =
true)
920 : State(std::make_shared<detail::RecDirIterState>()),
921 Follow(follow_symlinks) {
931 if (State->HasNoPushRequest)
932 State->HasNoPushRequest =
false;
935 if ((ec = State->Stack.top()->status(st)))
return *
this;
938 if (ec)
return *
this;
939 if (State->Stack.top() != end_itr) {
947 while (!State->Stack.empty()
948 && State->Stack.top().increment(ec) == end_itr) {
954 if (State->Stack.empty())
965 int level()
const {
return State->Level; }
973 assert(State &&
"Cannot pop an end iterator!");
974 assert(State->Level > 0 &&
"Cannot pop an iterator with level < 1");
983 }
while (!State->Stack.empty()
984 && State->Stack.top().increment(ec) == end_itr);
987 if (State->Stack.empty())
992 void no_push() { State->HasNoPushRequest =
true; }
995 return State == RHS.State;
999 return !(*
this == RHS);
1011 #endif // LLVM_SUPPORT_FILESYSTEM_H
recursive_directory_iterator()=default
std::error_code create_directories(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create all the non-existent directories in path.
F_Append - When opening a file, if it already exists append to the existing file instead of returning...
bool can_execute(const Twine &Path)
Can we execute this file?
const directory_entry * operator->() const
Represents either an error or a value T.
space_info - Self explanatory.
bool operator<=(const directory_entry &rhs) const
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, unsigned Mode=all_read|all_write)
Create a uniquely named file.
std::error_code openFileForRead(const Twine &Name, int &ResultFD, SmallVectorImpl< char > *RealPath=nullptr)
F_Excl - When opening a file, this flag makes raw_fd_ostream report an error if the file already exis...
recursive_directory_iterator(const Twine &path, std::error_code &ec, bool follow_symlinks=true)
bool operator==(const recursive_directory_iterator &RHS) const
bool operator!=(const UniqueID &Other) const
void replace_filename(const Twine &filename, file_status st=file_status())
void pop()
Goes up one level if Level > 0.
UniqueID getUniqueID() const
mapped_file_region & operator=(mapped_file_region &)=delete
bool operator<(const UniqueID &Other) const
This class represents a memory mapped file.
std::error_code setLastModificationAndAccessTime(int FD, TimePoint<> Time)
Set the file modification and access time.
std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
directory_iterator & increment(std::error_code &ec)
recursive_directory_iterator - Same as directory_iterator except for it recurses down into child dire...
bool operator!=(const directory_iterator &RHS) const
std::error_code remove_directories(const Twine &path, bool IgnoreErrors=true)
Recursively delete a directory.
const char * const_data() const
Get a const view of the data.
file_status - Represents the result of a call to stat and friends.
bool status_known(file_status s)
Is status available?
ErrorOr< MD5::MD5Result > md5_contents(int FD)
Compute an MD5 hash of a file's contents.
mapped_file_region()=delete
amode Optimize addressing mode
ErrorOr< perms > getPermissions(const Twine &Path)
Get file permissions.
std::error_code directory_iterator_increment(DirIterState &)
void permissions(perms p)
bool operator>=(const directory_entry &rhs) const
std::string str() const
Return the twine contents as a std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Keeps state for the directory_iterator.
directory_iterator(const Twine &path, std::error_code &ec, bool follow_symlinks=true)
bool operator==(const directory_entry &rhs) const
perms operator&(perms l, perms r)
bool operator!=(const directory_entry &rhs) const
std::error_code file_size(const Twine &Path, uint64_t &Result)
Get file size.
May access map via data and modify it. Written to path.
bool no_push_request() const
Returns true if no_push has been called for this directory_entry.
bool can_write(const Twine &Path)
Can we write this file?
directory_entry CurrentEntry
const directory_entry * operator->() const
May only access map via const_data as read only.
std::error_code is_local(const Twine &path, bool &result)
Is the file mounted on a local filesystem?
std::error_code create_link(const Twine &to, const Twine &from)
Create a link from from to to.
Open the file for read and write.
std::stack< directory_iterator, std::vector< directory_iterator > > Stack
directory_iterator(const directory_entry &de, std::error_code &ec, bool follow_symlinks=true)
bool is_symlink_file(file_status status)
Does status represent a symlink file?
std::string getMainExecutable(const char *argv0, void *MainExecAddr)
Return the path to the main executable, given the value of argv[0] from program startup and the addre...
std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
directory_entry(const Twine &path, bool follow_symlinks=true, file_status st=file_status())
std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
uint32_t getLinkCount() const
UniqueID(uint64_t Device, uint64_t File)
bool operator<(const directory_entry &rhs) const
The instances of the Type class are immutable: once they are created, they are never changed...
void no_push()
Does not go down into the current directory_entry.
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
void assign(const Twine &path, file_status st=file_status())
recursive_directory_iterator & increment(std::error_code &ec)
bool is_other(file_status status)
Does this status represent something that exists but is not a directory or regular file...
TimePoint getLastAccessedTime() const
std::error_code getUniqueID(const Twine Path, UniqueID &Result)
std::error_code resize_file(int FD, uint64_t Size)
Resize path to size.
file_type get_file_type(const Twine &Path, bool Follow=true)
Does status represent a directory?
const directory_entry & operator*() const
friend bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
std::error_code getPathFromOpenFD(int FD, SmallVectorImpl< char > &ResultPath)
Fetch a path to an open file, as specified by a file descriptor.
std::error_code make_absolute(const Twine ¤t_directory, SmallVectorImpl< char > &path)
Make path an absolute path.
std::error_code create_hard_link(const Twine &to, const Twine &from)
Create a hard link from from to to, or return an error.
const directory_entry & operator*() const
perms permissions() const
const std::string & path() const
perms operator|(perms l, perms r)
bool is_directory(file_status status)
Does status represent a directory?
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
Keeps state for the recursive_directory_iterator.
std::error_code directory_iterator_construct(DirIterState &, StringRef, bool)
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
std::error_code createUniqueDirectory(const Twine &Prefix, SmallVectorImpl< char > &ResultPath)
std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
std::error_code status(file_status &result) const
uint64_t getDevice() const
bool is_regular_file(file_status status)
Does status represent a regular file?
The file should be opened in text mode on platforms that make this distinction.
std::error_code set_current_path(const Twine &path)
Set the current path.
May modify via data, but changes are lost on destruction.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
bool operator!=(const recursive_directory_iterator &RHS) const
bool operator>(const directory_entry &rhs) const
static std::vector< std::string > Flags
ErrorOr< space_info > disk_space(const Twine &Path)
Get disk space usage information.
std::error_code directory_iterator_destruct(DirIterState &)
directory_iterator - Iterates through the entries in path.
file_type
An enumeration for the file system's view of the type.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
std::error_code createTemporaryFile(const Twine &Prefix, StringRef Suffix, int &ResultFD, SmallVectorImpl< char > &ResultPath)
Create a file in the system temporary directory.
TimePoint getLastModificationTime() const
std::error_code create_directory(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
int level() const
Gets the current level. Starting path is at level 0.
bool operator==(const UniqueID &Other) const
Provides ErrorOr<T> smart pointer.
bool operator==(const directory_iterator &RHS) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
perms & operator&=(perms &l, perms r)
bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
perms & operator|=(perms &l, perms r)
directory_entry()=default
directory_entry - A single entry in a directory.
std::error_code access(const Twine &Path, AccessMode Mode)
Can the file be accessed?
StringRef - Represent a constant reference to a string, i.e.
bool exists(file_status status)
Does file exist?
directory_iterator()=default
Construct end iterator.
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, OpenFlags Flags, unsigned Mode=0666)