From 740d41ce9f7fdf209366e930bd0fdcc6b1bc6b79 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 24 Jul 2019 03:21:25 +0300 Subject: [PATCH] Add CheckDataDirOption() function --- src/util/system.cpp | 11 +++++++++-- src/util/system.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/util/system.cpp b/src/util/system.cpp index d9e23199ec3..520ed35504e 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -741,8 +741,9 @@ const fs::path &GetDataDir(bool fNetSpecific) // this function if (!path.empty()) return path; - if (gArgs.IsArgSet("-datadir")) { - path = fs::system_complete(gArgs.GetArg("-datadir", "")); + std::string datadir = gArgs.GetArg("-datadir", ""); + if (!datadir.empty()) { + path = fs::system_complete(datadir); if (!fs::is_directory(path)) { path = ""; return path; @@ -761,6 +762,12 @@ const fs::path &GetDataDir(bool fNetSpecific) return path; } +bool CheckDataDirOption() +{ + std::string datadir = gArgs.GetArg("-datadir", ""); + return datadir.empty() || fs::is_directory(fs::system_complete(datadir)); +} + void ClearDatadirCache() { LOCK(csPathCached); diff --git a/src/util/system.h b/src/util/system.h index dda91564887..9ed9f1f0df3 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -83,6 +83,8 @@ fs::path GetDefaultDataDir(); // The blocks directory is always net specific. const fs::path &GetBlocksDir(); const fs::path &GetDataDir(bool fNetSpecific = true); +// Return true if -datadir option points to a valid directory or is not specified. +bool CheckDataDirOption(); /** Tests only */ void ClearDatadirCache(); fs::path GetConfigFile(const std::string& confPath);