diff --git a/src/util/asmap.cpp b/src/util/asmap.cpp --- a/src/util/asmap.cpp +++ b/src/util/asmap.cpp @@ -300,7 +300,8 @@ } fseek(filestr, 0, SEEK_END); int length = ftell(filestr); - LogPrintf("Opened asmap file %s (%d bytes) from disk\n", path, length); + LogPrintf("Opened asmap file %s (%d bytes) from disk\n", + fs::quoted(fs::PathToString(path)), length); fseek(filestr, 0, SEEK_SET); char cur_byte; for (int i = 0; i < length; ++i) { @@ -310,7 +311,8 @@ } } if (!SanityCheckASMap(bits, 128)) { - LogPrintf("Sanity check of asmap file %s failed\n", path); + LogPrintf("Sanity check of asmap file %s failed\n", + fs::quoted(fs::PathToString(path))); return {}; } return bits; diff --git a/src/util/settings.cpp b/src/util/settings.cpp --- a/src/util/settings.cpp +++ b/src/util/settings.cpp @@ -73,21 +73,21 @@ file.open(path); if (!file.is_open()) { errors.emplace_back( - strprintf("%s. Please check permissions.", path.string())); + strprintf("%s. Please check permissions.", fs::PathToString(path))); return false; } SettingsValue in; if (!in.read(std::string{std::istreambuf_iterator(file), std::istreambuf_iterator()})) { - errors.emplace_back( - strprintf("Unable to parse settings file %s", path.string())); + errors.emplace_back(strprintf("Unable to parse settings file %s", + fs::PathToString(path))); return false; } if (file.fail()) { - errors.emplace_back( - strprintf("Failed reading settings file %s", path.string())); + errors.emplace_back(strprintf("Failed reading settings file %s", + fs::PathToString(path))); return false; } // Done with file descriptor. Release while copying data. @@ -96,7 +96,7 @@ if (!in.isObject()) { errors.emplace_back( strprintf("Found non-object value %s in settings file %s", - in.write(), path.string())); + in.write(), fs::PathToString(path))); return false; } @@ -107,7 +107,7 @@ if (!inserted.second) { errors.emplace_back( strprintf("Found duplicate key %s in settings file %s", - in_keys[i], path.string())); + in_keys[i], fs::PathToString(path))); } } return errors.empty(); @@ -125,7 +125,7 @@ if (file.fail()) { errors.emplace_back( strprintf("Error: Unable to open settings file %s for writing", - path.string())); + fs::PathToString(path))); return false; } file << out.write(/* prettyIndent= */ 1, /* indentLevel= */ 4) << std::endl; diff --git a/src/util/system.cpp b/src/util/system.cpp --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -92,7 +92,7 @@ // If a lock for this directory already exists in the map, don't try to // re-lock it - if (dir_locks.count(pathLockFile.string())) { + if (dir_locks.count(fs::PathToString(pathLockFile))) { return true; } @@ -104,11 +104,11 @@ auto lock = std::make_unique(pathLockFile); if (!lock->TryLock()) { return error("Error while attempting to lock directory %s: %s", - directory.string(), lock->GetReason()); + fs::PathToString(directory), lock->GetReason()); } if (!probe_only) { // Lock successful and we're not just probing, put it into the map - dir_locks.emplace(pathLockFile.string(), std::move(lock)); + dir_locks.emplace(fs::PathToString(pathLockFile), std::move(lock)); } return true; } @@ -116,7 +116,7 @@ void UnlockDirectory(const fs::path &directory, const std::string &lockfile_name) { LOCK(cs_dir_locks); - dir_locks.erase((directory / lockfile_name).string()); + dir_locks.erase(fs::PathToString(directory / lockfile_name)); } void ReleaseDirectoryLocks() { @@ -244,7 +244,7 @@ namespace { fs::path StripRedundantLastElementsOfPath(const fs::path &path) { auto result = path; - while (result.filename().string() == ".") { + while (fs::PathToString(result.filename()) == ".") { result = result.parent_path(); } @@ -412,7 +412,8 @@ } if (IsArgSet("-blocksdir")) { - path = fs::system_complete(GetArg("-blocksdir", "")); + path = + fs::system_complete(fs::PathFromString(GetArg("-blocksdir", ""))); if (!fs::is_directory(path)) { path = ""; return path; @@ -421,7 +422,7 @@ path = GetDataDirPath(false); } - path /= BaseParams().DataDir(); + path /= fs::PathFromString(BaseParams().DataDir()); path /= "blocks"; fs::create_directories(path); path = StripRedundantLastElementsOfPath(path); @@ -440,7 +441,7 @@ } std::string datadir = GetArg("-datadir", ""); if (!datadir.empty()) { - path = fs::system_complete(datadir); + path = fs::system_complete(fs::PathFromString(datadir)); if (!fs::is_directory(path)) { path = ""; return path; @@ -449,7 +450,7 @@ path = GetDefaultDataDir(); } if (net_specific) { - path /= BaseParams().DataDir(); + path /= fs::PathFromString(BaseParams().DataDir()); } if (fs::create_directories(path)) { @@ -507,8 +508,9 @@ } if (filepath) { std::string settings = GetArg("-settings", BITCOIN_SETTINGS_FILENAME); - *filepath = fs::absolute(temp ? settings + ".tmp" : settings, - GetDataDirPath(/* net_specific= */ true)); + *filepath = fs::absolute( + fs::PathFromString(temp ? settings + ".tmp" : settings), + GetDataDirPath(/* net_specific= */ true)); } return true; } @@ -564,9 +566,10 @@ return false; } if (!RenameOver(path_tmp, path)) { - SaveErrors({strprintf("Failed renaming settings file %s to %s\n", - path_tmp.string(), path.string())}, - errors); + SaveErrors( + {strprintf("Failed renaming settings file %s to %s\n", + fs::PathToString(path_tmp), fs::PathToString(path))}, + errors); return false; } return true; @@ -831,11 +834,12 @@ bool CheckDataDirOption() { std::string datadir = gArgs.GetArg("-datadir", ""); - return datadir.empty() || fs::is_directory(fs::system_complete(datadir)); + return datadir.empty() || + fs::is_directory(fs::system_complete(fs::PathFromString(datadir))); } fs::path GetConfigFile(const std::string &confPath) { - return AbsPathForConfigVal(fs::path(confPath), false); + return AbsPathForConfigVal(fs::PathFromString(confPath), false); } static bool @@ -1118,7 +1122,7 @@ return MoveFileExA(src.string().c_str(), dest.string().c_str(), MOVEFILE_REPLACE_EXISTING) != 0; #else - int rc = std::rename(src.string().c_str(), dest.string().c_str()); + int rc = std::rename(src.c_str(), dest.c_str()); return (rc == 0); #endif /* WIN32 */ }