aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2022-02-04 17:57:51 +0200
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2022-02-09 19:31:16 +0200
commit540ca5111f7dc91a9808e41ccb4446d8dc0a1bec (patch)
tree9d956753b4de73919e9cbf1fd68490bc4440b113 /src/util
parent5e8e0b3d7f6055e326bda61e60712b530e8920f0 (diff)
downloadbitcoin-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.cpp7
-rw-r--r--src/util/system.h10
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