| |
| |
| |
| |
| |
|
|
| #ifndef MAMBA_FS_FILESYSTEM_HPP |
| #define MAMBA_FS_FILESYSTEM_HPP |
|
|
| #include <filesystem> |
| #include <string> |
|
|
| #include <fmt/format.h> |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| namespace mamba::fs |
| { |
| |
| class now |
| { |
| }; |
|
|
| struct Utf8Options |
| { |
| bool normalize_sep = true; |
| }; |
|
|
| |
| std::filesystem::path normalized_separators(std::filesystem::path path); |
|
|
| |
| std::string to_utf8(const std::filesystem::path& path, Utf8Options utf8_options = {}); |
|
|
| |
| std::filesystem::path from_utf8(std::string_view u8string); |
|
|
| |
| class u8path |
| { |
| public: |
|
|
| using value_type = char; |
| using string_type = std::basic_string<value_type>; |
|
|
| u8path() = default; |
|
|
| |
| u8path(const u8path& other) = default; |
| u8path& operator=(const u8path& other) = default; |
|
|
| |
| u8path(u8path&& other) = default; |
| u8path& operator=(u8path&& other) = default; |
|
|
| |
|
|
| u8path(const std::filesystem::path& path) |
| : m_path(normalized_separators(path)) |
| { |
| } |
|
|
| u8path& operator=(const std::filesystem::path& path) |
| { |
| m_path = normalized_separators(path); |
| return *this; |
| } |
|
|
| u8path& operator=(std::filesystem::path&& path) |
| { |
| m_path = normalized_separators(std::move(path)); |
| return *this; |
| } |
|
|
| u8path(std::string_view u8string) |
| : m_path(from_utf8(u8string)) |
| { |
| } |
|
|
| u8path& operator=(std::string_view u8string) |
| { |
| m_path = from_utf8(u8string); |
| return *this; |
| } |
|
|
| u8path(const char* u8string) |
| : m_path(from_utf8(u8string)) |
| { |
| } |
|
|
| u8path& operator=(const char* u8string) |
| { |
| m_path = from_utf8(u8string); |
| return *this; |
| } |
|
|
| u8path(const std::string& u8string) |
| : m_path(from_utf8(u8string)) |
| { |
| } |
|
|
| u8path& operator=(const std::string& u8string) |
| { |
| m_path = from_utf8(u8string); |
| return *this; |
| } |
|
|
| u8path& operator=(std::string&& u8string) |
| { |
| m_path = from_utf8(std::move(u8string)); |
| return *this; |
| } |
|
|
| |
|
|
| u8path(const wchar_t* wstr) |
| : m_path(normalized_separators(wstr)) |
| { |
| } |
|
|
| u8path& operator=(const wchar_t* wstr) |
| { |
| m_path = normalized_separators(wstr); |
| return *this; |
| } |
|
|
| u8path(const std::wstring& wstr) |
| : m_path(normalized_separators(wstr)) |
| { |
| } |
|
|
| u8path& operator=(const std::wstring& wstr) |
| { |
| m_path = normalized_separators(wstr); |
| return *this; |
| } |
|
|
| u8path& operator=(std::wstring&& wstr) |
| { |
| m_path = normalized_separators(std::move(wstr)); |
| return *this; |
| } |
|
|
| |
|
|
| u8path operator/(const u8path& p) const |
| { |
| return m_path / p.m_path; |
| } |
|
|
| u8path operator/(const std::filesystem::path& p) const |
| { |
| return m_path / normalized_separators(p); |
| } |
|
|
| u8path operator/(std::string_view str) const |
| { |
| return m_path / from_utf8(str); |
| } |
|
|
| u8path operator/(std::wstring_view wstr) const |
| { |
| return m_path / normalized_separators(wstr); |
| } |
|
|
| u8path operator/(const std::string& str) const |
| { |
| return m_path / from_utf8(str); |
| } |
|
|
| u8path operator/(const std::wstring& wstr) const |
| { |
| return m_path / normalized_separators(wstr); |
| } |
|
|
| u8path operator/(const char* str) const |
| { |
| return m_path / from_utf8(str); |
| } |
|
|
| u8path operator/(const wchar_t* wstr) const |
| { |
| return m_path / normalized_separators(wstr); |
| } |
|
|
| template <typename T> |
| u8path& operator/=(T&& some_string) |
| { |
| *this = *this / std::forward<T>(some_string); |
| return *this; |
| } |
|
|
| u8path& operator+=(const u8path& to_append) |
| { |
| m_path += to_append.m_path; |
| return *this; |
| } |
|
|
| u8path& operator+=(const std::filesystem::path& to_append) |
| { |
| m_path += normalized_separators(to_append); |
| return *this; |
| } |
|
|
| u8path& operator+=(std::string_view to_append) |
| { |
| m_path = from_utf8(this->string().append(to_append)); |
| return *this; |
| } |
|
|
| u8path& operator+=(std::wstring_view to_append) |
| { |
| m_path += normalized_separators(to_append); |
| return *this; |
| } |
|
|
| u8path& operator+=(const char* to_append) |
| { |
| m_path = from_utf8(this->string().append(to_append)); |
| return *this; |
| } |
|
|
| u8path& operator+=(const wchar_t* to_append) |
| { |
| m_path += normalized_separators(to_append); |
| return *this; |
| } |
|
|
| u8path& operator+=(const std::string& to_append) |
| { |
| m_path = from_utf8(this->string().append(to_append)); |
| return *this; |
| } |
|
|
| u8path& operator+=(const std::wstring& to_append) |
| { |
| m_path += normalized_separators(to_append); |
| return *this; |
| } |
|
|
| u8path& operator+=(char to_append) |
| { |
| m_path = from_utf8(this->string().append(1, to_append)); |
| return *this; |
| } |
|
|
| u8path& operator+=(wchar_t to_append) |
| { |
| m_path += to_append; |
| m_path = normalized_separators(std::move(m_path)); |
| return *this; |
| } |
|
|
| |
|
|
| |
| std::string string() const |
| { |
| return to_utf8(m_path, { true }); |
| } |
|
|
| |
| decltype(auto) native() const |
| { |
| return m_path.native(); |
| } |
|
|
| |
| operator std::string() const |
| { |
| return this->string(); |
| } |
|
|
| |
| std::wstring wstring() const |
| { |
| return m_path.wstring(); |
| } |
|
|
| |
| operator std::wstring() const |
| { |
| return this->wstring(); |
| } |
|
|
| |
| std::string generic_string() const |
| { |
| return to_utf8(m_path.generic_string(), { false }); |
| } |
|
|
| |
| operator std::filesystem::path() const |
| { |
| return m_path; |
| } |
|
|
| |
| const std::filesystem::path& std_path() const noexcept |
| { |
| return m_path; |
| } |
|
|
| |
|
|
| u8path stem() const |
| { |
| return m_path.stem(); |
| } |
|
|
| u8path parent_path() const |
| { |
| return m_path.parent_path(); |
| } |
|
|
| u8path root_name() const |
| { |
| return m_path.root_name(); |
| } |
|
|
| u8path root_directory() const |
| { |
| return m_path.root_directory(); |
| } |
|
|
| u8path root_path() const |
| { |
| return m_path.root_path(); |
| } |
|
|
| u8path filename() const |
| { |
| return m_path.filename(); |
| } |
|
|
| u8path extension() const |
| { |
| return m_path.extension(); |
| } |
|
|
| u8path lexically_normal() const |
| { |
| return m_path.lexically_normal(); |
| } |
|
|
| u8path lexically_relative(const u8path& base) const |
| { |
| return m_path.lexically_relative(base); |
| } |
|
|
| u8path lexically_proximate(const u8path& base) const |
| { |
| return m_path.lexically_proximate(base); |
| } |
|
|
| |
|
|
| void clear() noexcept |
| { |
| m_path.clear(); |
| } |
|
|
| u8path& remove_filename() |
| { |
| m_path.remove_filename(); |
| return *this; |
| } |
|
|
| u8path& replace_filename(const u8path replacement) |
| { |
| m_path.replace_filename(replacement.m_path); |
| return *this; |
| } |
|
|
| u8path& replace_extension(const u8path replacement = u8path()) |
| { |
| m_path.replace_extension(replacement.m_path); |
| return *this; |
| } |
|
|
| |
| friend bool operator==(const u8path& left, const u8path& right) noexcept |
| { |
| return left.m_path == right.m_path; |
| } |
|
|
| friend std::strong_ordering operator<=>(const u8path& left, const u8path& right) noexcept |
| { |
| return left.m_path <=> right.m_path; |
| } |
|
|
| friend bool operator==(const u8path& left, const std::filesystem::path& right) noexcept |
| { |
| return left.m_path == right; |
| } |
|
|
| friend std::strong_ordering |
| operator<=>(const u8path& left, const std::filesystem::path& right) noexcept |
| { |
| return left.m_path <=> right; |
| } |
|
|
| friend bool operator==(const u8path& left, const std::string& right) noexcept |
| { |
| return left.m_path == from_utf8(right); |
| } |
|
|
| friend std::strong_ordering operator<=>(const u8path& left, const std::string& right) noexcept |
| { |
| return left.m_path <=> from_utf8(right); |
| } |
|
|
| friend bool operator==(const u8path& left, const char* right) noexcept |
| { |
| return left.m_path == from_utf8(right); |
| } |
|
|
| friend std::strong_ordering operator<=>(const u8path& left, const char* right) noexcept |
| { |
| return left.m_path <=> from_utf8(right); |
| } |
|
|
| friend bool operator==(const u8path& left, const std::wstring& right) noexcept |
| { |
| return left.m_path == std::filesystem::path(right); |
| } |
|
|
| friend std::strong_ordering operator<=>(const u8path& left, const std::wstring& right) noexcept |
| { |
| return left.m_path <=> std::filesystem::path(right); |
| } |
|
|
| friend bool operator==(const u8path& left, const wchar_t* right) noexcept |
| { |
| return left.m_path == std::filesystem::path(right); |
| } |
|
|
| friend std::strong_ordering operator<=>(const u8path& left, const wchar_t* right) noexcept |
| { |
| return left.m_path <=> std::filesystem::path(right); |
| } |
|
|
| |
|
|
| bool empty() const noexcept |
| { |
| return m_path.empty(); |
| } |
|
|
| bool is_absolute() const |
| { |
| return m_path.is_absolute(); |
| } |
|
|
| bool is_relative() const |
| { |
| return m_path.is_relative(); |
| } |
|
|
| bool has_root_path() const |
| { |
| return m_path.has_root_path(); |
| } |
|
|
| bool has_root_name() const |
| { |
| return m_path.has_root_name(); |
| } |
|
|
| bool has_root_directory() const |
| { |
| return m_path.has_root_directory(); |
| } |
|
|
| bool has_relative_path() const |
| |
| { |
| return m_path.has_relative_path(); |
| } |
|
|
| bool has_parent_path() const |
| { |
| return m_path.has_parent_path(); |
| } |
|
|
| bool has_filename() const |
| { |
| return m_path.has_filename(); |
| } |
|
|
| bool has_stem() const |
| { |
| return m_path.has_stem(); |
| } |
|
|
| bool has_extension() const |
| { |
| return m_path.has_extension(); |
| } |
|
|
| |
|
|
| |
| |
| |
| template <typename OutStream> |
| friend OutStream& operator<<(OutStream& out, const u8path& path) |
| { |
| out << std::quoted(path.string()); |
| return out; |
| } |
|
|
| |
| template <typename InputStream> |
| friend InputStream& operator>>(InputStream& in, u8path& path) |
| { |
| std::string raw_input; |
| in >> std::quoted(raw_input); |
| path.m_path = from_utf8(raw_input); |
| return in; |
| } |
|
|
| friend std::size_t hash_value(const u8path& p) noexcept |
| { |
| return hash_value(p.m_path); |
| } |
|
|
| friend void swap(u8path& left, u8path& right) noexcept |
| { |
| swap(left.m_path, right.m_path); |
| } |
|
|
| private: |
|
|
| std::filesystem::path m_path; |
| }; |
|
|
| class directory_entry : private std::filesystem::directory_entry |
| { |
| public: |
|
|
| using std::filesystem::directory_entry::exists; |
| using std::filesystem::directory_entry::file_size; |
| using std::filesystem::directory_entry::hard_link_count; |
| using std::filesystem::directory_entry::is_block_file; |
| using std::filesystem::directory_entry::is_character_file; |
| using std::filesystem::directory_entry::is_directory; |
| using std::filesystem::directory_entry::is_fifo; |
| using std::filesystem::directory_entry::is_other; |
| using std::filesystem::directory_entry::is_regular_file; |
| using std::filesystem::directory_entry::is_socket; |
| using std::filesystem::directory_entry::is_symlink; |
| using std::filesystem::directory_entry::last_write_time; |
| using std::filesystem::directory_entry::status; |
| using std::filesystem::directory_entry::symlink_status; |
|
|
| directory_entry() = default; |
| directory_entry(const directory_entry&) = default; |
| directory_entry(directory_entry&&) noexcept = default; |
| directory_entry& operator=(const directory_entry&) = default; |
| directory_entry& operator=(directory_entry&&) noexcept = default; |
|
|
| template <typename... OtherArgs> |
| explicit directory_entry(const u8path& path, OtherArgs&&... args) |
| : std::filesystem::directory_entry(path.std_path(), std::forward<OtherArgs>(args)...) |
| { |
| } |
|
|
| directory_entry(const std::filesystem::directory_entry& other) |
| : std::filesystem::directory_entry(other) |
| { |
| } |
|
|
| directory_entry(std::filesystem::directory_entry&& other) |
| : std::filesystem::directory_entry(std::move(other)) |
| { |
| } |
|
|
| directory_entry& operator=(const std::filesystem::directory_entry& other) |
| { |
| std::filesystem::directory_entry::operator=(other); |
| return *this; |
| } |
|
|
| directory_entry& operator=(std::filesystem::directory_entry&& other) noexcept |
| { |
| std::filesystem::directory_entry::operator=(std::move(other)); |
| return *this; |
| } |
|
|
| std::strong_ordering operator<=>(const directory_entry& other) const noexcept |
| { |
| return std::filesystem::directory_entry::operator<=>(other); |
| } |
|
|
| u8path path() const |
| { |
| return std::filesystem::directory_entry::path(); |
| } |
|
|
| operator u8path() const noexcept |
| { |
| return std::filesystem::directory_entry::path(); |
| } |
|
|
| template <typename... OtherArgs> |
| void replace(const u8path p, OtherArgs&&... args) |
| { |
| std::filesystem::directory_entry::replace_filename(p, std::forward<OtherArgs>(args)...); |
| } |
| }; |
|
|
| static_assert(std::is_same_v<decltype(std::declval<directory_entry>().path()), u8path>); |
|
|
| class directory_iterator : private std::filesystem::directory_iterator |
| { |
| public: |
|
|
| using iterator_category = std::input_iterator_tag; |
| using value_type = directory_entry; |
| using difference_type = std::ptrdiff_t; |
| using pointer = const directory_entry*; |
| using reference = const directory_entry&; |
|
|
| directory_iterator() = default; |
| directory_iterator(const directory_iterator&) = default; |
| directory_iterator(directory_iterator&&) noexcept = default; |
| directory_iterator& operator=(const directory_iterator&) = default; |
| directory_iterator& operator=(directory_iterator&&) noexcept = default; |
|
|
| template <typename... OtherArgs> |
| explicit directory_iterator(const u8path& path, OtherArgs&&... args) |
| : std::filesystem::directory_iterator(path.std_path(), std::forward<OtherArgs>(args)...) |
| { |
| } |
|
|
| const directory_entry& operator*() const |
| { |
| current_entry = std::filesystem::directory_iterator::operator*(); |
| return current_entry; |
| } |
|
|
| const directory_entry* operator->() const |
| { |
| return &(**this); |
| } |
|
|
| directory_iterator& operator++() |
| { |
| std::filesystem::directory_iterator::operator++(); |
| return *this; |
| } |
|
|
| directory_iterator& increment(std::error_code& ec) |
| { |
| std::filesystem::directory_iterator::increment(ec); |
| return *this; |
| } |
|
|
| bool operator==(const directory_iterator& other) const noexcept |
| { |
| return static_cast<const std::filesystem::directory_iterator&>(*this) == other; |
| } |
|
|
| bool operator!=(const directory_iterator& other) const noexcept |
| { |
| return static_cast<const std::filesystem::directory_iterator&>(*this) != other; |
| } |
|
|
| private: |
|
|
| mutable directory_entry current_entry; |
| }; |
|
|
| static_assert(std::is_same_v<std::decay_t<decltype(*std::declval<directory_iterator>())>, directory_entry>); |
|
|
| inline directory_iterator begin(directory_iterator iter) noexcept |
| { |
| return iter; |
| } |
|
|
| inline directory_iterator end(directory_iterator) noexcept |
| { |
| return {}; |
| } |
|
|
| class recursive_directory_iterator : private std::filesystem::recursive_directory_iterator |
| { |
| public: |
|
|
| using iterator_category = std::input_iterator_tag; |
| using value_type = directory_entry; |
| using difference_type = std::ptrdiff_t; |
| using pointer = const directory_entry*; |
| using reference = const directory_entry&; |
|
|
| using std::filesystem::recursive_directory_iterator::depth; |
| using std::filesystem::recursive_directory_iterator::disable_recursion_pending; |
| using std::filesystem::recursive_directory_iterator::options; |
| using std::filesystem::recursive_directory_iterator::pop; |
| using std::filesystem::recursive_directory_iterator::recursion_pending; |
|
|
| recursive_directory_iterator() = default; |
| recursive_directory_iterator(const recursive_directory_iterator&) = default; |
| recursive_directory_iterator(recursive_directory_iterator&&) noexcept = default; |
| recursive_directory_iterator& operator=(const recursive_directory_iterator&) = default; |
| recursive_directory_iterator& operator=(recursive_directory_iterator&&) noexcept = default; |
|
|
| template <typename... OtherArgs> |
| explicit recursive_directory_iterator(const u8path& path, OtherArgs&&... args) |
| : std::filesystem::recursive_directory_iterator( |
| path.std_path(), |
| std::forward<OtherArgs>(args)... |
| ) |
| { |
| } |
|
|
| const directory_entry& operator*() const noexcept |
| { |
| current_entry = std::filesystem::recursive_directory_iterator::operator*(); |
| return current_entry; |
| } |
|
|
| const directory_entry* operator->() const noexcept |
| { |
| return &(**this); |
| } |
|
|
| recursive_directory_iterator& operator++() |
| { |
| std::filesystem::recursive_directory_iterator::operator++(); |
| return *this; |
| } |
|
|
| recursive_directory_iterator& increment(std::error_code& ec) |
| { |
| std::filesystem::recursive_directory_iterator::increment(ec); |
| return *this; |
| } |
|
|
| bool operator==(const recursive_directory_iterator& other) const noexcept |
| { |
| return static_cast<const std::filesystem::recursive_directory_iterator&>(*this) == other; |
| } |
|
|
| bool operator!=(const recursive_directory_iterator& other) const noexcept |
| { |
| return static_cast<const std::filesystem::recursive_directory_iterator&>(*this) != other; |
| } |
|
|
| private: |
|
|
| mutable directory_entry current_entry; |
| }; |
|
|
| static_assert(std::is_same_v<std::decay_t<decltype(*std::declval<directory_iterator>())>, directory_entry>); |
|
|
| inline recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept |
| { |
| return iter; |
| } |
|
|
| inline recursive_directory_iterator end(recursive_directory_iterator) noexcept |
| { |
| return {}; |
| } |
|
|
| |
|
|
| using std::filesystem::copy_options; |
| using std::filesystem::directory_options; |
| using std::filesystem::file_status; |
| using std::filesystem::file_time_type; |
| using std::filesystem::file_type; |
| using std::filesystem::filesystem_error; |
| using std::filesystem::perm_options; |
| using std::filesystem::perms; |
| using std::filesystem::space_info; |
|
|
| |
| |
|
|
| |
| |
| template <typename... OtherArgs> |
| u8path absolute(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::absolute(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| u8path canonical(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::canonical(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| |
| |
| template <typename... OtherArgs> |
| void copy(const u8path& from, const u8path& to, OtherArgs&&... args) |
| { |
| std::filesystem::copy(from, to, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| |
| |
| template <typename... OtherArgs> |
| bool copy_file(const u8path& from, const u8path& to, OtherArgs&&... args) |
| { |
| return std::filesystem::copy_file(from, to, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| |
| |
| template <typename... OtherArgs> |
| void copy_symlink(const u8path& existing_symlink, const u8path& new_symlink, OtherArgs&&... args) |
| { |
| std::filesystem::copy_symlink(existing_symlink, new_symlink, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool create_directories(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::create_directories(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool create_directory(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::create_directory(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool create_directory(const u8path& path, const u8path& attributes, OtherArgs&&... args) |
| { |
| return std::filesystem::create_directory(path, attributes, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| |
| template <typename... OtherArgs> |
| void create_directory_symlink(const u8path& to, const u8path& new_symlink, OtherArgs&&... args) |
| { |
| std::filesystem::create_directory_symlink(to, new_symlink, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| void create_hard_link(const u8path& to, const u8path& new_hard_link, OtherArgs&&... args) |
| { |
| std::filesystem::create_hard_link(to, new_hard_link, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| void create_symlink(const u8path& to, const u8path& new_symlink, OtherArgs&&... args) |
| { |
| std::filesystem::create_symlink(to, new_symlink, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| inline u8path current_path() |
| { |
| return std::filesystem::current_path(); |
| } |
|
|
| |
| inline u8path current_path(std::error_code& ec) |
| { |
| return std::filesystem::current_path(ec); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| void current_path(const u8path& path, OtherArgs&&... args) |
| { |
| std::filesystem::current_path(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool equivalent(const u8path& p1, const u8path& p2, OtherArgs&&... args) |
| { |
| return std::filesystem::equivalent(p1, p2, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| inline bool exists(file_status s) noexcept |
| { |
| return std::filesystem::exists(s); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool exists(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::exists(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| uintmax_t file_size(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::file_size(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| uintmax_t hard_link_count(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::hard_link_count(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| inline bool is_block_file(file_status s) noexcept |
| { |
| return std::filesystem::is_block_file(s); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool is_block_file(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::is_block_file(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| inline bool is_character_file(file_status s) noexcept |
| { |
| return std::filesystem::is_character_file(s); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool is_character_file(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::is_character_file(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| inline bool is_directory(file_status s) noexcept |
| { |
| return std::filesystem::is_directory(s); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool is_directory(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::is_directory(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool is_empty(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::is_empty(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| inline bool is_fifo(file_status s) noexcept |
| { |
| return std::filesystem::is_fifo(s); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool is_fifo(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::is_fifo(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| inline bool is_other(file_status s) noexcept |
| { |
| return std::filesystem::is_other(s); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool is_other(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::is_other(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| inline bool is_regular_file(file_status s) noexcept |
| { |
| return std::filesystem::is_regular_file(s); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool is_regular_file(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::is_regular_file(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| inline bool is_socket(file_status s) noexcept |
| { |
| return std::filesystem::is_socket(s); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool is_socket(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::is_socket(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| inline bool is_symlink(file_status s) noexcept |
| { |
| return std::filesystem::is_symlink(s); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool is_symlink(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::is_symlink(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| file_time_type last_write_time(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::last_write_time(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| void last_write_time(const u8path& path, now, std::error_code& ec) noexcept; |
|
|
| |
| inline void last_write_time(const u8path& path, now sentinel) |
| { |
| std::error_code ec; |
| last_write_time(path, sentinel, ec); |
| if (ec) |
| { |
| throw filesystem_error("last_write_time", path, ec); |
| } |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| void last_write_time(const u8path& path, file_time_type new_time, OtherArgs&&... args) |
| { |
| return std::filesystem::last_write_time(path, new_time, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| |
| template <typename... OtherArgs> |
| void permissions(const u8path& path, OtherArgs&&... args) |
| { |
| std::filesystem::permissions(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| u8path proximate(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::proximate(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| template <typename... OtherArgs> |
| u8path proximate(const u8path& path, const u8path& base, OtherArgs&&... args) |
| { |
| return std::filesystem::proximate(path, base, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| u8path read_symlink(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::read_symlink(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| u8path relative(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::relative(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| template <typename... OtherArgs> |
| u8path relative(const u8path& path, const u8path& base, OtherArgs&&... args) |
| { |
| return std::filesystem::relative(path, base, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| bool remove(const u8path& path, OtherArgs&&... args) |
| { |
| #if defined(WIN32) && _MSC_VER < 1930 |
| std::error_code errc; |
| const auto file_status = std::filesystem::status(path, errc); |
| if (!errc |
| && (file_status.permissions() & std::filesystem::perms::owner_read) |
| != std::filesystem::perms::none |
| && (file_status.permissions() & std::filesystem::perms::owner_write) |
| == std::filesystem::perms::none) |
| { |
| |
| |
| fs::permissions(path, fs::perms::owner_write, fs::perm_options::add); |
| } |
| #endif |
| return std::filesystem::remove(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| uintmax_t remove_all(const u8path& path, OtherArgs&&... args) |
| { |
| #if defined(WIN32) && _MSC_VER < 1930 |
| if (!fs::exists(path)) |
| { |
| return 0; |
| } |
|
|
| uintmax_t counter = 0; |
| for (const auto& entry : fs::recursive_directory_iterator(path, args...)) |
| { |
| if (fs::is_directory(entry.path())) |
| { |
| continue; |
| } |
|
|
| if (fs::remove(entry.path(), args...)) |
| { |
| ++counter; |
| } |
| else |
| { |
| break; |
| } |
| } |
|
|
| |
| counter += std::filesystem::remove_all(path, args...); |
|
|
| return counter; |
| #else |
| return std::filesystem::remove_all(path, std::forward<OtherArgs>(args)...); |
| #endif |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| void rename(const u8path& from, const u8path& to, OtherArgs&&... args) |
| { |
| std::filesystem::rename(from, to, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| void resize_file(const u8path& path, OtherArgs&&... args) |
| { |
| std::filesystem::resize_file(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| space_info space(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::space(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| file_status status(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::status(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| inline bool status_known(file_status s) noexcept |
| { |
| return std::filesystem::status_known(s); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| file_status symlink_status(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::symlink_status(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| u8path temp_directory_path(OtherArgs&&... args) |
| { |
| return std::filesystem::temp_directory_path(std::forward<OtherArgs>(args)...); |
| } |
|
|
| |
| |
| template <typename... OtherArgs> |
| u8path weakly_canonical(const u8path& path, OtherArgs&&... args) |
| { |
| return std::filesystem::weakly_canonical(path, std::forward<OtherArgs>(args)...); |
| } |
|
|
| } |
|
|
| template <> |
| struct std::hash<::mamba::fs::u8path> |
| { |
| std::size_t operator()(const ::mamba::fs::u8path& path) const noexcept |
| { |
| return std::filesystem::hash_value(path.std_path() |
| ); |
| |
| } |
| }; |
|
|
| template <> |
| struct fmt::formatter<::mamba::fs::u8path> |
| { |
| constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) |
| { |
| |
| if (ctx.begin() != ctx.end() && *ctx.begin() != '}') |
| { |
| throw format_error("invalid format"); |
| } |
| return ctx.begin(); |
| } |
|
|
| template <class FormatContext> |
| auto format(const ::mamba::fs::u8path& path, FormatContext& ctx) const |
| { |
| return fmt::format_to(ctx.out(), "'{}'", path.string()); |
| } |
| }; |
| #endif |
|
|