5#ifndef BITCOIN_UTIL_FS_H
6#define BITCOIN_UTIL_FS_H
24using namespace std::filesystem;
32class path :
public std::filesystem::path
35 using std::filesystem::path::path;
38 std::filesystem::path&
std_path() {
return *
this; }
39 const std::filesystem::path&
std_path()
const {
return *
this; }
43 path&
operator=(std::filesystem::path
path) { std::filesystem::path::operator=(std::move(
path));
return *
this; }
48 path&
operator=(
const char*
c) { std::filesystem::path::operator=(
c);
return *
this; }
49 path&
operator/=(
const char*
c) { std::filesystem::path::operator/=(
c);
return *
this; }
50 path&
append(
const char*
c) { std::filesystem::path::append(
c);
return *
this; }
53 path(std::string) =
delete;
75 const std::u8string&
utf8_str{std::filesystem::path::u8string()};
82 return std::filesystem::path(std::u8string{
utf8_str.begin(),
utf8_str.end()});
98static inline bool exists(
const std::filesystem::file_status& s)
104static inline auto quoted(
const std::string& s)
106 return std::quoted(s,
'"',
'&');
120static inline path operator+(path
p1,
const char*
p2)
125static inline path operator+(path
p1, path::value_type
p2)
133template<
typename T>
static inline path operator+(path
p1,
T p2) =
delete;
173 return path.utf8string();
175 static_assert(std::is_same_v<path::string_type, std::string>,
"PathToString not implemented on this platform");
176 return path.std::filesystem::path::string();
188 return std::filesystem::path(
string);
195 using FopenFn = std::function<
FILE*(
const fs::path&,
const char*)>;
196 FILE *
fopen(
const fs::path&
p,
const char *mode);
207 fs::path
AbsPathJoin(
const fs::path& base,
const fs::path& path);
215 explicit FileLock(
const fs::path& file);
225 void*
hFile = (
void*)-1;
233template<>
inline void formatValue(std::ostream&,
const char*,
const char*,
int,
const std::filesystem::path&) =
delete;
234template<>
inline void formatValue(std::ostream&,
const char*,
const char*,
int,
const fs::path&) =
delete;
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
const std::filesystem::path & std_path() const
path(std::filesystem::path path)
path & operator=(std::string)=delete
std::filesystem::path & std_path()
std::string string() const =delete
path & operator/=(const std::filesystem::path &path)
path & operator/=(std::string)=delete
std::string utf8string() const
Return a UTF-8 representation of the path as a std::string, for compatibility with code using std::st...
path & append(std::string)=delete
path & operator=(std::filesystem::path path)
path & append(const char *c)
path & operator=(const char *c)
path & operator/=(const char *c)
FileLock(FileLock &&)=delete
FileLock(const FileLock &)=delete
static path absolute(const path &p)
static path u8path(std::string_view utf8_str)
static auto quoted(const std::string &s)
static bool exists(const path &p)
static bool copy_file(const path &from, const path &to, copy_options options)
static std::string PathToString(const path &path)
Convert path object to a byte string.
static path PathFromString(const std::string &string)
Convert byte string to path object.
static path operator/(path p1, const path &p2)
#define T(expected, seed, data)
Bridge operations to C stdio.
FILE * fopen(const fs::path &p, const char *mode)
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
std::function< FILE *(const fs::path &, const char *)> FopenFn
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.