5 #ifndef BITCOIN_UTIL_FS_H 6 #define BITCOIN_UTIL_FS_H 17 #include <string_view> 18 #include <system_error> 19 #include <type_traits> 33 class path :
public std::filesystem::path
36 using std::filesystem::path::path;
39 std::filesystem::path&
std_path() {
return *
this; }
40 const std::filesystem::path&
std_path()
const {
return *
this; }
44 path&
operator=(std::filesystem::path
path) { std::filesystem::path::operator=(std::move(
path));
return *
this; }
49 path&
operator=(
const char* c) { std::filesystem::path::operator=(c);
return *
this; }
50 path&
operator/=(
const char* c) { std::filesystem::path::operator/=(c);
return *
this; }
51 path&
append(
const char* c) { std::filesystem::path::append(c);
return *
this; }
54 path(std::string) =
delete;
55 path& operator=(std::string) =
delete;
56 path& operator/=(std::string) =
delete;
57 path& append(std::string) =
delete;
60 std::string string()
const =
delete;
66 operator string_type()
const =
delete;
76 const std::u8string& utf8_str{std::filesystem::path::u8string()};
77 return std::string{utf8_str.begin(), utf8_str.end()};
81 static inline path
u8path(std::string_view utf8_str)
83 return std::filesystem::path(std::u8string{utf8_str.begin(), utf8_str.end()});
95 static inline bool exists(
const path& p)
101 static inline auto quoted(
const std::string&
s)
103 return std::quoted(
s,
'"',
'&');
122 static inline path
operator+(path p1, path::value_type p2)
129 template<
typename T>
static inline path
operator/(path p1, T p2) =
delete;
130 template<
typename T>
static inline path
operator+(path p1, T p2) =
delete;
134 static inline bool copy_file(
const path& from,
const path& to, copy_options options)
170 return path.utf8string();
172 static_assert(std::is_same_v<path::string_type, std::string>,
"PathToString not implemented on this platform");
173 return path.std::filesystem::path::string();
185 return std::filesystem::path(
string);
192 using FopenFn = std::function<FILE*(const fs::path&, const char*)>;
222 void* hFile = (
void*)-1;
230 template<>
inline void formatValue(std::ostream&,
const char*,
const char*,
int,
const std::filesystem::path&) =
delete;
231 template<>
inline void formatValue(std::ostream&,
const char*,
const char*,
int,
const fs::path&) =
delete;
234 #endif // BITCOIN_UTIL_FS_H static path absolute(const path &p)
path & append(const char *c)
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
FILE * fopen(const fs::path &p, const char *mode)
Bridge operations to C stdio.
path & operator/=(const std::filesystem::path &path)
std::function< FILE *(const fs::path &, const char *)> FopenFn
static bool exists(const path &p)
const std::filesystem::path & std_path() const
bilingual_str operator+(bilingual_str lhs, const bilingual_str &rhs)
path & operator/=(const char *c)
static bool copy_file(const path &from, const path &to, copy_options options)
path(std::filesystem::path path)
path & operator=(const char *c)
std::string utf8string() const
Return a UTF-8 representation of the path as a std::string, for compatibility with code using std::st...
static auto quoted(const std::string &s)
static std::string PathToString(const path &path)
Convert path object to a byte string.
static path operator/(path p1, const path &p2)
static path u8path(std::string_view utf8_str)
static path PathFromString(const std::string &string)
Convert byte string to path object.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
path & operator=(std::filesystem::path path)
std::filesystem::path & std_path()