15#include <system_error>
21namespace swoc {
inline namespace SWOC_VERSION_NS {
24using file_time_type = std::chrono::system_clock::time_point;
26enum class file_type :
signed char {
40static constexpr int NO_FD = -1;
85 operator int()
const {
return _fd; }
94 using self_type =
path;
104 path(
const self_type &that) =
default;
107 path(self_type &&that) =
default;
110 explicit path(
const char *src);
113 path(std::string_view src);
116 path(std::string
const &p);
119 path(std::string &&that);
128 self_type &
operator=(std::string_view p);
131 self_type &
operator=(std::string
const &s);
182 char const *
c_str()
const;
185 std::string
const &
string()
const;
218 friend self_type
status(
const path &file, std::error_code &ec)
noexcept;
220 friend uintmax_t
file_size(
const self_type &);
222 friend bool is_dir(
const self_type &);
225 friend bool exists(
const self_type &);
243[[deprecated(
"Use file_status::type")]]
int file_type(
const file_status &fs);
388 _path.assign(std::move(s));
400 return _path.c_str();
403inline std::string
const &
415 return _path.empty();
430 return *
this /= std::string_view(that.
_path);
457 return path(lhs) /= rhs;
466 return path(std::move(lhs)) /= rhs;
475 return path(lhs) /= rhs;
490 return path(std::move(lhs)) /= rhs;
501 return _stat.st_mode;
506 return fs._type == file_type::character;
511 return fs._type == file_type::block;
516 return fs._type == file_type::regular;
521 return fs._type == file_type::directory;
526 return fs._type != file_type::none && fs._type != file_type::not_found;
545template <>
struct hash<
swoc::file::path> {
548 return hash<string_view>()(path.
view());
Information about a file.
friend bool is_dir(const self_type &)
Check if the path is to a directory.
friend file_time_type last_write_time(file_status const &fs)
friend bool is_block_device(const self_type &)
Check if the path is to a block device.
friend file_time_type access_time(file_status const &fs)
friend bool is_regular_file(const self_type &)
Check if the path is to a regular file.
friend bool exists(const self_type &)
Check if path exists.
friend bool is_char_device(const self_type &)
Check if the path is to a character device.
struct::stat _stat
File information.
friend uintmax_t file_size(const self_type &)
Size of the file or block device.
friend self_type status(const path &file, std::error_code &ec) noexcept
friend int file_type(const self_type &)
Return the file type value.
friend file_time_type status_time(file_status const &fs)
self_type & operator=(const self_type &that)=default
Replace the path with a copy of that.
bool empty() const
Check if the path is empty.
self_type & operator=(self_type &&that)=default
Replace the path with the contents of that.
static constexpr char SEPARATOR
Default path separator.
path(self_type &&that)=default
Move constructor.
path(const self_type &that)=default
Copy constructor - copies the path.
swoc::TextView view() const
A view of the path.
self_type & reserve(size_t n)
char const * c_str() const
Access the path explicitly.
self_type relative_path() const
self_type filename() const
self_type & operator/=(const self_type &that)
std::string _path
File path.
self_type parent_path() const
Path of the parent.
bool is_relative() const
Check if the path is not absolute.
std::string const & string() const
The path as a string.
bool is_absolute() const
Check if the path is absolute.
path()=default
Default construct empty path.
For template deduction guides.
BufferWriter & bwformat(BufferWriter &w, bwf::Spec const &spec, std::string_view sv)
unique_fd self_type
Self reference type.
unique_fd(self_type const &)=delete
Non-copyable.
~unique_fd()
Close the file dscriptor.
unique_fd(self_type &&that)
bool exists(const path &p)
Check if path exists.
uintmax_t file_size(const file_status &fs)
Size of the file or block device.
path temp_directory_path()
Directory location suitable for temporary files.
uintmax_t remove_all(const path &p, std::error_code &ec)
file_time_type last_write_time(file_status const &fs)
std::string load(const path &p, std::error_code &ec)
bool copy(const path &from, const path &to, std::error_code &ec)
bool create_directories(const path &p, std::error_code &ec, mode_t mode) noexcept
file_time_type access_time(file_status const &fs)
bool is_readable(const path &p)
Check if file is readable.
path absolute(path const &src, std::error_code &ec)
path canonical(const path &p, std::error_code &ec)
bool create_directory(const path &path, std::error_code &ec, mode_t mode) noexcept
bool remove(path const &p, std::error_code &ec)
file_status status(path const &file, std::error_code &ec) noexcept
path current_path()
Current working directory.
file_time_type status_time(file_status const &fs)
file_time_type modify_time(file_status const &fs)
path operator/(const path &lhs, const path &rhs)
bool is_block_device(const file_status &fs)
Check if the path is to a block device.
bool is_char_device(const file_status &fs)
Check if the path is to a character device.
bool operator!=(path const &lhs, path const &rhs)
bool operator==(path const &lhs, path const &rhs)
bool is_regular_file(const file_status &fs)
Check if the path is to a regular file.
bool is_dir(const file_status &p)
Check if the path is to a directory.