diff options
author | Kiminuo <kiminuo@protonmail.com> | 2020-06-11 08:58:46 +0200 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2022-02-03 18:35:52 +0800 |
commit | 41d7166c8a598b604aad6c6b1d88ad46e23be247 (patch) | |
tree | 883af805ab387dc7db01602a19ccd70d89b78cb1 /src/util/system.cpp | |
parent | ffc89d1f21258553c0087b774a9ea1ce84139d4f (diff) |
refactor: replace boost::filesystem with std::filesystem
Warning: Replacing fs::system_complete calls with fs::absolute calls
in this commit may cause minor changes in behaviour because fs::absolute
no longer strips trailing slashes; however these changes are believed to
be safe.
Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
Diffstat (limited to 'src/util/system.cpp')
-rw-r--r-- | src/util/system.cpp | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp index 19de08d1ea..0ee63f6381 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -10,6 +10,7 @@ #endif // ENABLE_EXTERNAL_SIGNER #include <chainparamsbase.h> +#include <fs.h> #include <sync.h> #include <util/check.h> #include <util/getuniquepath.h> @@ -66,10 +67,15 @@ #endif #include <boost/algorithm/string/replace.hpp> +#include <univalue.h> + +#include <fstream> +#include <map> +#include <memory> #include <optional> +#include <string> #include <thread> #include <typeinfo> -#include <univalue.h> // Application startup time (used for uptime calculation) const int64_t nStartupTime = GetTime(); @@ -146,7 +152,7 @@ bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes) } std::streampos GetFileSize(const char* path, std::streamsize max) { - fsbridge::ifstream file{path, std::ios::binary}; + std::ifstream file{path, std::ios::binary}; file.ignore(max); return file.gcount(); } @@ -243,7 +249,7 @@ namespace { fs::path StripRedundantLastElementsOfPath(const fs::path& path) { auto result = path; - while (fs::PathToString(result.filename()) == ".") { + while (result.filename().empty() || fs::PathToString(result.filename()) == ".") { result = result.parent_path(); } @@ -403,7 +409,7 @@ const fs::path& ArgsManager::GetBlocksDirPath() const if (!path.empty()) return path; if (IsArgSet("-blocksdir")) { - path = fs::system_complete(fs::PathFromString(GetArg("-blocksdir", ""))); + path = fs::absolute(fs::PathFromString(GetArg("-blocksdir", ""))); if (!fs::is_directory(path)) { path = ""; return path; @@ -415,7 +421,6 @@ const fs::path& ArgsManager::GetBlocksDirPath() const path /= fs::PathFromString(BaseParams().DataDir()); path /= "blocks"; fs::create_directories(path); - path = StripRedundantLastElementsOfPath(path); return path; } @@ -430,7 +435,7 @@ const fs::path& ArgsManager::GetDataDir(bool net_specific) const std::string datadir = GetArg("-datadir", ""); if (!datadir.empty()) { - path = fs::system_complete(fs::PathFromString(datadir)); + path = fs::absolute(StripRedundantLastElementsOfPath(fs::PathFromString(datadir))); if (!fs::is_directory(path)) { path = ""; return path; @@ -808,7 +813,7 @@ fs::path GetDefaultDataDir() bool CheckDataDirOption() { std::string datadir = gArgs.GetArg("-datadir", ""); - return datadir.empty() || fs::is_directory(fs::system_complete(fs::PathFromString(datadir))); + return datadir.empty() || fs::is_directory(fs::absolute(fs::PathFromString(datadir))); } fs::path GetConfigFile(const std::string& confPath) @@ -898,7 +903,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) } const std::string confPath = GetArg("-conf", BITCOIN_CONF_FILENAME); - fsbridge::ifstream stream(GetConfigFile(confPath)); + std::ifstream stream{GetConfigFile(confPath)}; // not ok to have a config file specified that cannot be opened if (IsArgSet("-conf") && !stream.good()) { @@ -945,7 +950,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) const size_t default_includes = add_includes({}); for (const std::string& conf_file_name : conf_file_names) { - fsbridge::ifstream conf_file_stream(GetConfigFile(conf_file_name)); + std::ifstream conf_file_stream{GetConfigFile(conf_file_name)}; if (conf_file_stream.good()) { if (!ReadConfigStream(conf_file_stream, conf_file_name, error, ignore_invalid_keys)) { return false; @@ -1069,7 +1074,7 @@ bool RenameOver(fs::path src, fs::path dest) } /** - * Ignores exceptions thrown by Boost's create_directories if the requested directory exists. + * Ignores exceptions thrown by create_directories if the requested directory exists. * Specifically handles case where path p exists, but it wasn't possible for the user to * write to the parent directory. */ @@ -1313,16 +1318,6 @@ void SetupEnvironment() SetConsoleCP(CP_UTF8); SetConsoleOutputCP(CP_UTF8); #endif - // The path locale is lazy initialized and to avoid deinitialization errors - // in multithreading environments, it is set explicitly by the main thread. - // A dummy locale is used to extract the internal default locale, used by - // fs::path, which is then used to explicitly imbue the path. - std::locale loc = fs::path::imbue(std::locale::classic()); -#ifndef WIN32 - fs::path::imbue(loc); -#else - fs::path::imbue(std::locale(loc, new std::codecvt_utf8_utf16<wchar_t>())); -#endif } bool SetupNetworking() |