27 #ifndef LLVM_SUPPORT_FILESYSTEM_H 28 #define LLVM_SUPPORT_FILESYSTEM_H 33 #include "llvm/Config/llvm-config.h" 45 #include <system_error> 49 #ifdef HAVE_SYS_STAT_H 114 return static_cast<perms>(
static_cast<unsigned short>(l) |
115 static_cast<unsigned short>(r));
118 return static_cast<perms>(
static_cast<unsigned short>(l) &
119 static_cast<unsigned short>(r));
131 return static_cast<perms>(
132 static_cast<unsigned short>(~static_cast<
unsigned short>(x)));
141 UniqueID(uint64_t Device, uint64_t File) : Device(Device), File(File) {}
144 return Device == Other.Device && File == Other.File;
148 return std::tie(Device, File) < std::tie(Other.Device, Other.File);
160 #if defined(LLVM_ON_UNIX) 161 time_t fs_st_atime = 0;
162 time_t fs_st_mtime = 0;
165 off_t fs_st_size = 0;
166 #elif defined (_WIN32) 182 #if defined(LLVM_ON_UNIX) 184 uid_t UID, gid_t GID, off_t
Size)
185 : fs_st_atime(ATime), fs_st_mtime(MTime), fs_st_uid(UID), fs_st_gid(GID),
186 fs_st_size(Size), Type(Type), Perms(Perms) {}
187 #elif defined(_WIN32) 192 : LastAccessedTimeHigh(LastAccessTimeHigh),
193 LastAccessedTimeLow(LastAccessTimeLow),
194 LastWriteTimeHigh(LastWriteTimeHigh),
195 LastWriteTimeLow(LastWriteTimeLow), FileSizeHigh(FileSizeHigh),
196 FileSizeLow(FileSizeLow),
Type(Type), Perms(Perms) {}
205 #if defined(LLVM_ON_UNIX) 208 uint64_t
getSize()
const {
return fs_st_size; }
209 #elif defined (_WIN32) 218 uint64_t getSize()
const {
219 return (uint64_t(FileSizeHigh) << 32) + FileSizeLow;
232 #if defined(LLVM_ON_UNIX) 234 nlink_t fs_st_nlinks = 0;
236 #elif defined (_WIN32) 248 #if defined(LLVM_ON_UNIX) 250 time_t ATime, time_t MTime, uid_t UID, gid_t GID, off_t
Size)
252 fs_st_dev(Dev), fs_st_nlinks(Links), fs_st_ino(Ino) {}
253 #elif defined(_WIN32) 261 LastWriteTimeHigh, LastWriteTimeLow, FileSizeHigh,
263 NumLinks(LinkCount), VolumeSerialNumber(VolumeSerialNumber),
264 FileIndexHigh(FileIndexHigh), FileIndexLow(FileIndexLow) {}
309 bool IgnoreExisting =
true,
350 bool expand_tilde =
false);
372 std::error_code
remove(
const Twine &path,
bool IgnoreNonExisting =
true);
503 std::error_code
is_local(
int FD,
bool &result);
509 return !
is_local(Path, Result) && Result;
516 return !
is_local(FD, Result) && Result;
657 std::error_code EC =
status(Path, Status);
661 return std::error_code();
848 return OpenFlags(
unsigned(A) |
unsigned(B));
901 unsigned Mode = 0666);
918 inline std::error_code
941 unsigned Mode = 0666) {
963 unsigned Mode = 0666) {
983 unsigned Mode = 0666) {
1071 std::error_code &ec);
1075 size_t size()
const;
1080 const char *const_data()
const;
1083 static int alignment();
1100 bool FollowSymlinks;
1106 : Path(path.str()), FollowSymlinks(follow_symlinks), Status(st) {}
1118 const std::string &
path()
const {
return Path; }
1153 std::shared_ptr<detail::DirIterState> State;
1154 bool FollowSymlinks =
true;
1158 bool follow_symlinks =
true)
1159 : FollowSymlinks(follow_symlinks) {
1160 State = std::make_shared<detail::DirIterState>();
1163 *State, path.
toStringRef(path_storage), FollowSymlinks);
1164 update_error_code_for_current_entry(ec);
1168 bool follow_symlinks =
true)
1169 : FollowSymlinks(follow_symlinks) {
1170 State = std::make_shared<detail::DirIterState>();
1172 *State, de.
path(), FollowSymlinks);
1173 update_error_code_for_current_entry(ec);
1182 update_error_code_for_current_entry(ec);
1190 if (State == RHS.State)
1196 return State->CurrentEntry == RHS.State->CurrentEntry;
1200 return !(*
this == RHS);
1208 void update_error_code_for_current_entry(std::error_code &ec) {
1228 std::stack<directory_iterator, std::vector<directory_iterator>>
Stack;
1230 bool HasNoPushRequest =
false;
1238 std::shared_ptr<detail::RecDirIterState> State;
1244 bool follow_symlinks =
true)
1245 : State(
std::make_shared<detail::RecDirIterState>()),
1246 Follow(follow_symlinks) {
1256 if (State->HasNoPushRequest)
1257 State->HasNoPushRequest =
false;
1262 if (State->Stack.top() != end_itr) {
1270 while (!State->Stack.empty()
1271 && State->Stack.top().increment(ec) == end_itr) {
1277 if (State->Stack.empty())
1288 int level()
const {
return State->Level; }
1296 assert(State &&
"Cannot pop an end iterator!");
1297 assert(State->Level > 0 &&
"Cannot pop an iterator with level < 1");
1306 }
while (!State->Stack.empty()
1307 && State->Stack.top().increment(ec) == end_itr);
1310 if (State->Stack.empty())
1315 void no_push() { State->HasNoPushRequest =
true; }
1318 return State == RHS.State;
1322 return !(*
this == RHS);
1334 #endif // LLVM_SUPPORT_FILESYSTEM_H
const file_t kInvalidFile
const directory_entry & operator*() const
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.
bool can_execute(const Twine &Path)
Can we execute this file?
std::error_code openFileForReadWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
Represents either an error or a value T.
space_info - Self explanatory.
Expected< file_t > openNativeFileForWrite(const Twine &Name, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
bool status_known(const basic_file_status &s)
Is status available?
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Compute iterated dominance frontiers using a linear time algorithm.
bool operator<(const UniqueID &Other) const
std::error_code openFileForRead(const Twine &Name, int &ResultFD, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
void closeFile(file_t &F)
Close the file object.
directory_entry(const Twine &path, bool follow_symlinks=true, basic_file_status st=basic_file_status())
std::error_code createUniqueFile(const Twine &Model, int &ResultFD, SmallVectorImpl< char > &ResultPath, unsigned Mode=all_read|all_write)
Create a uniquely named file.
perms permissions() const
bool operator>(int64_t V1, const APSInt &V2)
recursive_directory_iterator(const Twine &path, std::error_code &ec, bool follow_symlinks=true)
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
void pop()
Goes up one level if Level > 0.
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.
bool is_directory(const basic_file_status &status)
Does status represent a directory?
Expected< file_t > openNativeFile(const Twine &Name, CreationDisposition Disp, FileAccess Access, OpenFlags Flags, unsigned Mode=0666)
Opens a file with the specified creation disposition, access mode, and flags and returns a platform-s...
bool is_regular_file(const basic_file_status &status)
Does status represent a regular file?
directory_iterator & increment(std::error_code &ec)
recursive_directory_iterator - Same as directory_iterator except for it recurses down into child dire...
std::error_code remove_directories(const Twine &path, bool IgnoreErrors=true)
Recursively delete a directory.
Represents the result of a call to sys::fs::status().
CD_OpenAlways - When opening a file:
ErrorOr< MD5::MD5Result > md5_contents(int FD)
Compute an MD5 hash of a file's contents.
bool operator<=(int64_t V1, const APSInt &V2)
amode Optimize addressing mode
ErrorOr< perms > getPermissions(const Twine &Path)
Get file permissions.
std::error_code directory_iterator_increment(DirIterState &)
perms operator &(perms l, perms r)
perms & operator &=(perms &l, perms r)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool operator>=(int64_t V1, const APSInt &V2)
Keeps state for the directory_iterator.
directory_iterator(const Twine &path, std::error_code &ec, bool follow_symlinks=true)
bool operator<(uint32_t Value, UnicodeCharRange Range)
Represents a temporary file.
std::error_code file_size(const Twine &Path, uint64_t &Result)
Get file size.
const directory_entry & operator*() const
Tagged union holding either a T or a Error.
May access map via data and modify it. Written to path.
bool can_write(const Twine &Path)
Can we write this file?
directory_entry CurrentEntry
When a child process is launched, this file should remain open in the child process.
May only access map via const_data as read only.
CD_CreateNew - When opening a file:
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.
std::stack< directory_iterator, std::vector< directory_iterator > > Stack
directory_iterator(const directory_entry &de, std::error_code &ec, bool follow_symlinks=true)
Delete the file on close. Only makes a difference on windows.
The file should be opened in text mode on platforms that make this distinction.
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...
bool operator!=(const directory_iterator &RHS) const
Represents the result of a call to directory_iterator::status().
std::error_code copy_file(const Twine &From, const Twine &To)
Copy the contents of From to To.
const directory_entry * operator->() const
std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
initializer< Ty > init(const Ty &Val)
bool operator==(const directory_entry &rhs) const
UniqueID(uint64_t Device, uint64_t File)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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.
file_status(file_type Type)
std::error_code status(const Twine &path, file_status &result, bool follow=true)
Get file status as if by POSIX stat().
recursive_directory_iterator & increment(std::error_code &ec)
Expected< file_t > openNativeFileForReadWrite(const Twine &Name, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
std::error_code getError() const
bool operator!=(const UniqueID &Other) const
std::error_code getUniqueID(const Twine Path, UniqueID &Result)
std::error_code resize_file(int FD, uint64_t Size)
Resize path to size.
const directory_entry * operator->() const
file_type get_file_type(const Twine &Path, bool Follow=true)
Does status represent a directory?
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.
basic_file_status(file_type Type)
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
perms operator|(perms l, perms r)
Force files Atime to be updated on access. Only makes a difference on windows.
const std::string & path() const
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
Keeps state for the recursive_directory_iterator.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
std::error_code directory_iterator_construct(DirIterState &, StringRef, bool)
bool operator==(const recursive_directory_iterator &RHS) const
The file should be opened in append mode.
std::error_code createUniqueDirectory(const Twine &Prefix, SmallVectorImpl< char > &ResultPath)
Expected< file_t > openNativeFileForRead(const Twine &Name, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
std::error_code setPermissions(const Twine &Path, perms Permissions)
Set file permissions.
bool is_other(const basic_file_status &status)
Does this status represent something that exists but is not a directory or regular file...
file_status(file_type Type, perms Perms, dev_t Dev, nlink_t Links, ino_t Ino, time_t ATime, time_t MTime, uid_t UID, gid_t GID, off_t Size)
uint32_t getGroup() const
std::error_code set_current_path(const Twine &path)
Set the current path.
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.
bool operator!=(const recursive_directory_iterator &RHS) const
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.
void permissions(perms p)
bool operator==(const directory_iterator &RHS) const
std::error_code getPotentiallyUniqueTempFileName(const Twine &Prefix, StringRef Suffix, SmallVectorImpl< char > &ResultPath)
Get a unique temporary file name, not currently exisiting in the filesystem.
uint64_t getDevice() const
std::error_code create_directory(const Twine &path, bool IgnoreExisting=true, perms Perms=owner_all|group_all)
Create the directory in path.
bool operator==(const UniqueID &Other) const
std::string str() const
Return the twine contents as a std::string.
std::error_code getPotentiallyUniqueFileName(const Twine &Model, SmallVectorImpl< char > &ResultPath)
Get a unique name, not currently exisiting in the filesystem.
Provides ErrorOr<T> smart pointer.
void assign(const Twine &path, basic_file_status st=basic_file_status())
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool equivalent(file_status A, file_status B)
Do file_status's represent the same thing?
CD_CreateAlways - When opening a file:
perms & operator|=(perms &l, perms r)
std::error_code openFile(const Twine &Name, int &ResultFD, CreationDisposition Disp, FileAccess Access, OpenFlags Flags, unsigned Mode=0666)
Opens a file with the specified creation disposition, access mode, and flags and returns a file descr...
int level() const
Gets the current level. Starting path is at level 0.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Lightweight error class with error context and mandatory checking.
bool no_push_request() const
Returns true if no_push has been called for this directory_entry.
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.
CD_OpenAlways - When opening a file:
bool is_symlink_file(const basic_file_status &status)
Does status represent a symlink file?
bool exists(const basic_file_status &status)
Does file exist?
basic_file_status(file_type Type, perms Perms, time_t ATime, time_t MTime, uid_t UID, gid_t GID, off_t Size)
std::chrono::time_point< std::chrono::system_clock, D > TimePoint
A time point on the system clock.