Skip to content

Commit 740d41c

Browse files
committed
Add CheckDataDirOption() function
1 parent c1f3251 commit 740d41c

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/util/system.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,9 @@ const fs::path &GetDataDir(bool fNetSpecific)
741741
// this function
742742
if (!path.empty()) return path;
743743

744-
if (gArgs.IsArgSet("-datadir")) {
745-
path = fs::system_complete(gArgs.GetArg("-datadir", ""));
744+
std::string datadir = gArgs.GetArg("-datadir", "");
745+
if (!datadir.empty()) {
746+
path = fs::system_complete(datadir);
746747
if (!fs::is_directory(path)) {
747748
path = "";
748749
return path;
@@ -761,6 +762,12 @@ const fs::path &GetDataDir(bool fNetSpecific)
761762
return path;
762763
}
763764

765+
bool CheckDataDirOption()
766+
{
767+
std::string datadir = gArgs.GetArg("-datadir", "");
768+
return datadir.empty() || fs::is_directory(fs::system_complete(datadir));
769+
}
770+
764771
void ClearDatadirCache()
765772
{
766773
LOCK(csPathCached);

src/util/system.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ fs::path GetDefaultDataDir();
8383
// The blocks directory is always net specific.
8484
const fs::path &GetBlocksDir();
8585
const fs::path &GetDataDir(bool fNetSpecific = true);
86+
// Return true if -datadir option points to a valid directory or is not specified.
87+
bool CheckDataDirOption();
8688
/** Tests only */
8789
void ClearDatadirCache();
8890
fs::path GetConfigFile(const std::string& confPath);

0 commit comments

Comments
 (0)