Changeset View
Changeset View
Standalone View
Standalone View
src/util/system.cpp
Show First 20 Lines • Show All 844 Lines • ▼ Show 20 Lines | const fs::path &GetDataDir(bool fNetSpecific) { | ||||
fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached; | fs::path &path = fNetSpecific ? pathCachedNetSpecific : pathCached; | ||||
// 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()) { | ||||
return path; | return path; | ||||
} | } | ||||
if (gArgs.IsArgSet("-datadir")) { | std::string datadir = gArgs.GetArg("-datadir", ""); | ||||
path = fs::system_complete(gArgs.GetArg("-datadir", "")); | if (!datadir.empty()) { | ||||
path = fs::system_complete(datadir); | |||||
if (!fs::is_directory(path)) { | if (!fs::is_directory(path)) { | ||||
path = ""; | path = ""; | ||||
return path; | return path; | ||||
} | } | ||||
} else { | } else { | ||||
path = GetDefaultDataDir(); | path = GetDefaultDataDir(); | ||||
} | } | ||||
Show All 10 Lines | if (fs::create_directories(path)) { | ||||
// See more info at: | // See more info at: | ||||
// https://reviews.bitcoinabc.org/D3312 | // https://reviews.bitcoinabc.org/D3312 | ||||
fs::create_directories(path / "wallets"); | fs::create_directories(path / "wallets"); | ||||
} | } | ||||
return path; | return path; | ||||
} | } | ||||
bool CheckDataDirOption() { | |||||
std::string datadir = gArgs.GetArg("-datadir", ""); | |||||
return datadir.empty() || fs::is_directory(fs::system_complete(datadir)); | |||||
} | |||||
void ClearDatadirCache() { | void ClearDatadirCache() { | ||||
LOCK(csPathCached); | LOCK(csPathCached); | ||||
pathCached = fs::path(); | pathCached = fs::path(); | ||||
pathCachedNetSpecific = fs::path(); | pathCachedNetSpecific = fs::path(); | ||||
g_blocks_path_cache_net_specific = fs::path(); | g_blocks_path_cache_net_specific = fs::path(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | if (stream.good()) { | ||||
"files; ignoring -includeconf=%s\n", | "files; ignoring -includeconf=%s\n", | ||||
to_include.c_str()); | to_include.c_str()); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// If datadir is changed in .conf file: | // If datadir is changed in .conf file: | ||||
ClearDatadirCache(); | ClearDatadirCache(); | ||||
if (!fs::is_directory(GetDataDir(false))) { | if (!CheckDataDirOption()) { | ||||
error = strprintf("specified data directory \"%s\" does not exist.", | error = strprintf("specified data directory \"%s\" does not exist.", | ||||
gArgs.GetArg("-datadir", "").c_str()); | gArgs.GetArg("-datadir", "").c_str()); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
std::string ArgsManager::GetChainName() const { | std::string ArgsManager::GetChainName() const { | ||||
▲ Show 20 Lines • Show All 257 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
// Obtain the application startup time (used for uptime calculation) | // Obtain the application startup time (used for uptime calculation) | ||||
int64_t GetStartupTime() { | int64_t GetStartupTime() { | ||||
return nStartupTime; | return nStartupTime; | ||||
} | } | ||||
fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific) { | fs::path AbsPathForConfigVal(const fs::path &path, bool net_specific) { | ||||
if (path.is_absolute()) { | |||||
return path; | |||||
} | |||||
return fs::absolute(path, GetDataDir(net_specific)); | return fs::absolute(path, GetDataDir(net_specific)); | ||||
} | } | ||||
int ScheduleBatchPriority() { | int ScheduleBatchPriority() { | ||||
#ifdef SCHED_BATCH | #ifdef SCHED_BATCH | ||||
const static sched_param param{}; | const static sched_param param{}; | ||||
if (int ret = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m)) { | if (int ret = pthread_setschedparam(pthread_self(), SCHED_BATCH, ¶m)) { | ||||
LogPrintf("Failed to pthread_setschedparam: %s\n", strerror(errno)); | LogPrintf("Failed to pthread_setschedparam: %s\n", strerror(errno)); | ||||
Show All 31 Lines |