diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2022-02-04 17:57:51 +0200 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2022-02-09 19:31:16 +0200 |
commit | 540ca5111f7dc91a9808e41ccb4446d8dc0a1bec (patch) | |
tree | 9d956753b4de73919e9cbf1fd68490bc4440b113 /src/util | |
parent | 5e8e0b3d7f6055e326bda61e60712b530e8920f0 (diff) | |
download | bitcoin-540ca5111f7dc91a9808e41ccb4446d8dc0a1bec.tar.xz |
util: Add ArgsManager::GetPathArg() function
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/system.cpp | 7 | ||||
-rw-r--r-- | src/util/system.h | 10 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp index 4ead39dd6c..82770dc665 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -399,6 +399,13 @@ std::optional<unsigned int> ArgsManager::GetArgFlags(const std::string& name) co return std::nullopt; } +fs::path ArgsManager::GetPathArg(std::string pathlike_arg) const +{ + auto result = fs::PathFromString(GetArg(pathlike_arg, "")).lexically_normal(); + // Remove trailing slash, if present. + return result.has_filename() ? result : result.parent_path(); +} + const fs::path& ArgsManager::GetBlocksDirPath() const { LOCK(cs_args); diff --git a/src/util/system.h b/src/util/system.h index a8fd21fcaa..6b7bd38cc2 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -265,6 +265,16 @@ protected: std::optional<const Command> GetCommand() const; /** + * Get a normalized path from a specified pathlike argument + * + * It is guaranteed that the returned path has no trailing slashes. + * + * @param pathlike_arg Pathlike argument to get a path from (e.g., "-datadir", "-blocksdir" or "-walletdir") + * @return Normalized path which is get from a specified pathlike argument + */ + fs::path GetPathArg(std::string pathlike_arg) const; + + /** * Get blocks directory path * * @return Blocks path which is network specific |