diff options
author | James O'Beirne <james.obeirne@gmail.com> | 2018-01-30 22:33:49 -0500 |
---|---|---|
committer | James O'Beirne <james.obeirne@gmail.com> | 2018-02-05 17:48:59 -0500 |
commit | 54604600c3de6cb18540c0911127173f68ad246c (patch) | |
tree | b778b12ff044d505836aac17225354451e950515 | |
parent | a1e13055c2c57913d8d57ca0978cef2fec1e6148 (diff) |
Add AbsPathForConfigVal to consolidate datadir prefixing for path args
Most commandline/config args are interpreted as relative to datadir if
not passed absolute. Consolidate the logic for this normalization.
-rw-r--r-- | src/rpc/protocol.cpp | 4 | ||||
-rw-r--r-- | src/util.cpp | 22 | ||||
-rw-r--r-- | src/util.h | 10 |
3 files changed, 20 insertions, 16 deletions
diff --git a/src/rpc/protocol.cpp b/src/rpc/protocol.cpp index ddc1bb6232..cdd2e67a69 100644 --- a/src/rpc/protocol.cpp +++ b/src/rpc/protocol.cpp @@ -72,9 +72,7 @@ static fs::path GetAuthCookieFile(bool temp=false) if (temp) { arg += ".tmp"; } - fs::path path(arg); - if (!path.is_complete()) path = GetDataDir() / path; - return path; + return AbsPathForConfigVal(fs::path(arg)); } bool GenerateAuthCookie(std::string *cookie_out) diff --git a/src/util.cpp b/src/util.cpp index 80eed24ffd..6738bbc6e4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -4,6 +4,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include <util.h> +#include <fs.h> #include <chainparamsbase.h> #include <random.h> @@ -188,11 +189,7 @@ static void DebugPrintInit() fs::path GetDebugLogPath() { fs::path logfile(gArgs.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE)); - if (logfile.is_absolute()) { - return logfile; - } else { - return GetDataDir() / logfile; - } + return AbsPathForConfigVal(logfile); } bool OpenDebugLog() @@ -624,11 +621,7 @@ void ClearDatadirCache() fs::path GetConfigFile(const std::string& confPath) { - fs::path pathConfigFile(confPath); - if (!pathConfigFile.is_complete()) - pathConfigFile = GetDataDir(false) / pathConfigFile; - - return pathConfigFile; + return AbsPathForConfigVal(fs::path(confPath), false); } void ArgsManager::ReadConfigFile(const std::string& confPath) @@ -663,9 +656,7 @@ void ArgsManager::ReadConfigFile(const std::string& confPath) #ifndef WIN32 fs::path GetPidFile() { - fs::path pathPidFile(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME)); - if (!pathPidFile.is_complete()) pathPidFile = GetDataDir() / pathPidFile; - return pathPidFile; + return AbsPathForConfigVal(fs::path(gArgs.GetArg("-pid", BITCOIN_PID_FILENAME))); } void CreatePidFile(const fs::path &path, pid_t pid) @@ -936,3 +927,8 @@ int64_t GetStartupTime() { return nStartupTime; } + +fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific) +{ + return fs::absolute(path, GetDataDir(net_specific)); +} diff --git a/src/util.h b/src/util.h index 277b4c66af..05138a9bfe 100644 --- a/src/util.h +++ b/src/util.h @@ -191,6 +191,16 @@ bool OpenDebugLog(); void ShrinkDebugFile(); void runCommand(const std::string& strCommand); +/** + * Most paths passed as configuration arguments are treated as relative to + * the datadir if they are not absolute. + * + * @param path The path to be conditionally prefixed with datadir. + * @param net_specific Forwarded to GetDataDir(). + * @return The normalized path. + */ +fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific = true); + inline bool IsSwitchChar(char c) { #ifdef WIN32 |