5#ifndef BITCOIN_UTIL_FS_H
6#define BITCOIN_UTIL_FS_H
22using namespace std::filesystem;
30class path :
public std::filesystem::path {
32 using std::filesystem::path::path;
37 std::filesystem::path::operator=(std::move(
path));
41 std::filesystem::path::operator/=(std::move(
path));
49 std::filesystem::path::operator=(
c);
53 std::filesystem::path::operator/=(
c);
57 std::filesystem::path::append(
c);
63 path(std::string) =
delete;
73 const auto &
utf8_str{std::filesystem::path::u8string()};
84 std::filesystem::path::make_preferred();
87 path filename()
const {
return std::filesystem::path::filename(); }
91 return std::filesystem::u8path(
utf8_str);
97 return std::filesystem::absolute(
p);
103 return std::filesystem::exists(
p);
107static inline auto quoted(
const std::string &s) {
108 return std::quoted(s,
'"',
'&');
121 return std::filesystem::copy_file(
from,
to, options);
156 static_assert(std::is_same<path::string_type, std::string>::value,
157 "PathToString not implemented on this platform");
158 return path.std::filesystem::path::string();
169 return std::filesystem::path(
string);
180 if (std::filesystem::is_symlink(
p) && std::filesystem::is_directory(
p)) {
183 return std::filesystem::create_directories(
p);
192 std::error_code &
ec) =
delete;
230 void *
hFile = (
void *)-1;
243inline void formatValue(std::ostream &,
const char *,
const char *,
int,
244 const std::filesystem::path &) =
delete;
246inline void formatValue(std::ostream &,
const char *,
const char *,
int,
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
path & operator/=(std::filesystem::path path)
path(std::filesystem::path path)
path & operator=(std::string)=delete
std::string string() const =delete
std::string u8string() const
path & operator/=(std::string)=delete
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
Filesystem operations and types.
static path absolute(const path &p)
static path u8path(const std::string &utf8_str)
static bool create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
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 byte string.
static path PathFromString(const std::string &string)
Convert byte string to path object.
static path operator+(path p1, path p2)
Bridge operations to C stdio.
fs::path GetTempDirectoryPath()
FILE * fopen(const fs::path &p, const char *mode)
std::string get_filesystem_error_message(const fs::filesystem_error &e)
FILE * freopen(const fs::path &p, const char *mode, FILE *stream)
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
Implement std::hash so RCUPtr can be used as a key for maps or sets.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...