Bitcoin Core 29.99.0
P2P Digital Currency
Classes | Namespaces | Typedefs | Functions
fs.h File Reference
#include <tinyformat.h>
#include <cstdio>
#include <filesystem>
#include <functional>
#include <iomanip>
#include <ios>
#include <ostream>
#include <string>
#include <system_error>
#include <type_traits>
#include <utility>
Include dependency graph for fs.h:

Go to the source code of this file.

Classes

class  fs::path
 Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path::string() method, which have unsafe and unpredictable behavior on Windows (see implementation note in PathToString for details) More...
 
class  fsbridge::FileLock
 

Namespaces

namespace  fs
 Filesystem operations and types.
 
namespace  fsbridge
 Bridge operations to C stdio.
 
namespace  tinyformat
 

Typedefs

using fsbridge::FopenFn = std::function< FILE *(const fs::path &, const char *)>
 

Functions

static path std::filesystem::u8path (const std::string &utf8_str)
 
static path std::filesystem::absolute (const path &p)
 
static bool std::filesystem::exists (const path &p)
 
static auto std::filesystem::quoted (const std::string &s)
 
static path std::filesystem::operator/ (path p1, const path &p2)
 
static path std::filesystem::operator/ (path p1, const char *p2)
 
static path std::filesystem::operator+ (path p1, const char *p2)
 
static path std::filesystem::operator+ (path p1, path::value_type p2)
 
template<typename T >
static path std::filesystem::operator/ (path p1, T p2)=delete
 
template<typename T >
static path std::filesystem::operator+ (path p1, T p2)=delete
 
static bool std::filesystem::copy_file (const path &from, const path &to, copy_options options)
 
static std::string std::filesystem::PathToString (const path &path)
 Convert path object to a byte string. More...
 
static path std::filesystem::PathFromString (const std::string &string)
 Convert byte string to path object. More...
 
static bool std::filesystem::create_directories (const std::filesystem::path &p)
 Create directory (and if necessary its parents), unless the leaf directory already exists or is a symlink to an existing directory. More...
 
bool std::filesystem::create_directories (const std::filesystem::path &p, std::error_code &ec)=delete
 This variant is not used. More...
 
FILE * fsbridge::fopen (const fs::path &p, const char *mode)
 
fs::path fsbridge::AbsPathJoin (const fs::path &base, const fs::path &path)
 Helper function for joining two paths. More...
 
std::string fsbridge::get_filesystem_error_message (const fs::filesystem_error &e)
 
template<>
void tinyformat::formatValue (std::ostream &, const char *, const char *, int, const std::filesystem::path &)=delete
 
template<>
void tinyformat::formatValue (std::ostream &, const char *, const char *, int, const fs::path &)=delete
 

Function Documentation

◆ absolute()

static path fs::absolute ( const path &  p)
inlinestatic

Definition at line 82 of file fs.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_file()

static bool fs::copy_file ( const path &  from,
const path &  to,
copy_options  options 
)
inlinestatic

Definition at line 128 of file fs.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_directories() [1/2]

static bool fs::create_directories ( const std::filesystem::path &  p)
inlinestatic

Create directory (and if necessary its parents), unless the leaf directory already exists or is a symlink to an existing directory.

This is a temporary workaround for an issue in libstdc++ that has been fixed upstream [PR101510]. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101510

Definition at line 190 of file fs.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_directories() [2/2]

bool fs::create_directories ( const std::filesystem::path &  p,
std::error_code &  ec 
)
delete

This variant is not used.

Delete it to prevent it from accidentally working around the workaround. If it is needed, add a workaround in the same pattern as above.

Here is the call graph for this function:

◆ exists()

static bool fs::exists ( const path &  p)
inlinestatic

Definition at line 89 of file fs.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator+() [1/3]

static path fs::operator+ ( path  p1,
const char *  p2 
)
inlinestatic

Definition at line 111 of file fs.h.

◆ operator+() [2/3]

static path fs::operator+ ( path  p1,
path::value_type  p2 
)
inlinestatic

Definition at line 116 of file fs.h.

◆ operator+() [3/3]

template<typename T >
static path fs::operator+ ( path  p1,
p2 
)
inlinestaticdelete

◆ operator/() [1/3]

static path fs::operator/ ( path  p1,
const char *  p2 
)
inlinestatic

Definition at line 106 of file fs.h.

Here is the call graph for this function:

◆ operator/() [2/3]

static path fs::operator/ ( path  p1,
const path &  p2 
)
inlinestatic

Definition at line 101 of file fs.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator/() [3/3]

template<typename T >
static path fs::operator/ ( path  p1,
p2 
)
inlinestaticdelete
Here is the call graph for this function:

◆ PathFromString()

static path fs::PathFromString ( const std::string &  string)
inlinestatic

Convert byte string to path object.

Inverse of PathToString.

Definition at line 174 of file fs.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PathToString()

static std::string fs::PathToString ( const path &  path)
inlinestatic

Convert path object to a byte string.

On POSIX, paths natively are byte strings, so this is trivial. On Windows, paths natively are Unicode, so an encoding step is necessary. The inverse of PathToString is PathFromString. The strings returned and parsed by these functions can be used to call POSIX APIs, and for roundtrip conversion, logging, and debugging.

Because PathToString and PathFromString functions don't specify an encoding, they are meant to be used internally, not externally. They are not appropriate to use in applications requiring UTF-8, where fs::path::u8string() / fs::path::utf8string() and fs::u8path() methods should be used instead. Other applications could require still different encodings. For example, JSON, XML, or URI applications might prefer to use higher-level escapes (\uXXXX or &XXXX; or XX) instead of multibyte encoding. Rust, Python, Java applications may require encoding paths with their respective UTF-8 derivatives WTF-8, PEP-383, and CESU-8 (see https://en.wikipedia.org/wiki/UTF-8#Derivatives).

Definition at line 151 of file fs.h.

Here is the call graph for this function:

◆ quoted()

static auto fs::quoted ( const std::string &  s)
inlinestatic

Definition at line 95 of file fs.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ u8path()

static path fs::u8path ( const std::string &  utf8_str)
inlinestatic

Definition at line 75 of file fs.h.

Here is the call graph for this function:
Here is the caller graph for this function: