Changeset View
Changeset View
Standalone View
Standalone View
src/util/system.cpp
Show First 20 Lines • Show All 395 Lines • ▼ Show 20 Lines | for (const auto &arg_map : m_available_args) { | ||||
const auto search = arg_map.second.find(name); | const auto search = arg_map.second.find(name); | ||||
if (search != arg_map.second.end()) { | if (search != arg_map.second.end()) { | ||||
return search->second.m_flags; | return search->second.m_flags; | ||||
} | } | ||||
} | } | ||||
return std::nullopt; | return std::nullopt; | ||||
} | } | ||||
const fs::path &ArgsManager::GetBlocksDirPath() { | |||||
LOCK(cs_args); | |||||
fs::path &path = m_cached_blocks_path; | |||||
// Cache the path to avoid calling fs::create_directories on every call of | |||||
// this function | |||||
if (!path.empty()) { | |||||
return path; | |||||
} | |||||
if (IsArgSet("-blocksdir")) { | |||||
path = fs::system_complete(GetArg("-blocksdir", "")); | |||||
if (!fs::is_directory(path)) { | |||||
path = ""; | |||||
return path; | |||||
} | |||||
} else { | |||||
path = GetDataDirPath(false); | |||||
} | |||||
path /= BaseParams().DataDir(); | |||||
path /= "blocks"; | |||||
fs::create_directories(path); | |||||
path = StripRedundantLastElementsOfPath(path); | |||||
return path; | |||||
} | |||||
const fs::path &ArgsManager::GetDataDirPath(bool net_specific) const { | const fs::path &ArgsManager::GetDataDirPath(bool net_specific) const { | ||||
LOCK(cs_args); | LOCK(cs_args); | ||||
fs::path &path = | fs::path &path = | ||||
net_specific ? m_cached_network_datadir_path : m_cached_datadir_path; | net_specific ? m_cached_network_datadir_path : m_cached_datadir_path; | ||||
// Cache the path to avoid calling fs::create_directories on every call of | // Cache the path to avoid calling fs::create_directories on every call of | ||||
// this function | // this function | ||||
if (!path.empty()) { | if (!path.empty()) { | ||||
Show All 22 Lines | const fs::path &ArgsManager::GetDataDirPath(bool net_specific) const { | ||||
return path; | return path; | ||||
} | } | ||||
void ArgsManager::ClearDatadirPathCache() { | void ArgsManager::ClearDatadirPathCache() { | ||||
LOCK(cs_args); | LOCK(cs_args); | ||||
m_cached_datadir_path = fs::path(); | m_cached_datadir_path = fs::path(); | ||||
m_cached_network_datadir_path = fs::path(); | m_cached_network_datadir_path = fs::path(); | ||||
m_cached_blocks_path = fs::path(); | |||||
} | } | ||||
std::vector<std::string> ArgsManager::GetArgs(const std::string &strArg) const { | std::vector<std::string> ArgsManager::GetArgs(const std::string &strArg) const { | ||||
std::vector<std::string> result; | std::vector<std::string> result; | ||||
for (const util::SettingsValue &value : GetSettingsList(strArg)) { | for (const util::SettingsValue &value : GetSettingsList(strArg)) { | ||||
result.push_back( | result.push_back( | ||||
value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str()); | value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 342 Lines • ▼ Show 20 Lines | #ifdef MAC_OSX | ||||
return pathRet / "Library/Application Support/Bitcoin"; | return pathRet / "Library/Application Support/Bitcoin"; | ||||
#else | #else | ||||
// Unix-like | // Unix-like | ||||
return pathRet / ".bitcoin"; | return pathRet / ".bitcoin"; | ||||
#endif | #endif | ||||
#endif | #endif | ||||
} | } | ||||
static fs::path g_blocks_path_cache_net_specific; | |||||
static RecursiveMutex csPathCached; | |||||
const fs::path &GetBlocksDir() { | |||||
LOCK(csPathCached); | |||||
fs::path &path = g_blocks_path_cache_net_specific; | |||||
// Cache the path to avoid calling fs::create_directories on every call of | |||||
// this function | |||||
if (!path.empty()) { | |||||
return path; | |||||
} | |||||
if (gArgs.IsArgSet("-blocksdir")) { | |||||
path = fs::system_complete(gArgs.GetArg("-blocksdir", "")); | |||||
if (!fs::is_directory(path)) { | |||||
path = ""; | |||||
return path; | |||||
} | |||||
} else { | |||||
path = GetDataDir(false); | |||||
} | |||||
path /= BaseParams().DataDir(); | |||||
path /= "blocks"; | |||||
fs::create_directories(path); | |||||
path = StripRedundantLastElementsOfPath(path); | |||||
return path; | |||||
} | |||||
const fs::path &GetDataDir(bool fNetSpecific) { | const fs::path &GetDataDir(bool fNetSpecific) { | ||||
return gArgs.GetDataDirPath(fNetSpecific); | return gArgs.GetDataDirPath(fNetSpecific); | ||||
} | } | ||||
bool CheckDataDirOption() { | bool CheckDataDirOption() { | ||||
std::string datadir = gArgs.GetArg("-datadir", ""); | 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(datadir)); | ||||
} | } | ||||
void ClearDatadirCache() { | void ClearDatadirCache() { | ||||
gArgs.ClearDatadirPathCache(); | gArgs.ClearDatadirPathCache(); | ||||
g_blocks_path_cache_net_specific = fs::path(); | |||||
} | } | ||||
fs::path GetConfigFile(const std::string &confPath) { | fs::path GetConfigFile(const std::string &confPath) { | ||||
return AbsPathForConfigVal(fs::path(confPath), false); | return AbsPathForConfigVal(fs::path(confPath), false); | ||||
} | } | ||||
static bool | static bool | ||||
GetConfigOptions(std::istream &stream, const std::string &filepath, | GetConfigOptions(std::istream &stream, const std::string &filepath, | ||||
▲ Show 20 Lines • Show All 574 Lines • Show Last 20 Lines |