Don't try to create empty datadir before the real path is known (#1494)

Fixes: #1345

The actual problem is that GetDataDir has the side effect of creating the
datadir, even if it is not known yet where it really is. This is only
known after reading the config file or when explicitly specified in the
cmd line.

Thus, if GetDataDir gets called before the datadir value from the config
is read, it tries to create it at the default location.
This commit is contained in:
Alexander Block 2017-06-26 15:57:16 +02:00 committed by UdjinM6
parent 5d27950296
commit 1d67d52122
2 changed files with 13 additions and 2 deletions

View File

@ -92,7 +92,8 @@ static int AppInitRPC(int argc, char* argv[])
}
return EXIT_SUCCESS;
}
if (!boost::filesystem::is_directory(GetDataDir(false))) {
bool datadirFromCmdLine = mapArgs.count("-datadir") != 0;
if (datadirFromCmdLine && !boost::filesystem::is_directory(GetDataDir(false))) {
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
return EXIT_FAILURE;
}
@ -102,6 +103,10 @@ static int AppInitRPC(int argc, char* argv[])
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return EXIT_FAILURE;
}
if (!datadirFromCmdLine && !boost::filesystem::is_directory(GetDataDir(false))) {
fprintf(stderr, "Error: Specified data directory \"%s\" from config file does not exist.\n", mapArgs["-datadir"].c_str());
return EXIT_FAILURE;
}
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
try {
SelectBaseParams(ChainNameFromCommandLine());

View File

@ -96,7 +96,8 @@ bool AppInit(int argc, char* argv[])
try
{
if (!boost::filesystem::is_directory(GetDataDir(false)))
bool datadirFromCmdLine = mapArgs.count("-datadir") != 0;
if (datadirFromCmdLine && !boost::filesystem::is_directory(GetDataDir(false)))
{
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
return false;
@ -108,6 +109,11 @@ bool AppInit(int argc, char* argv[])
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return false;
}
if (!datadirFromCmdLine && !boost::filesystem::is_directory(GetDataDir(false)))
{
fprintf(stderr, "Error: Specified data directory \"%s\" from config file does not exist.\n", mapArgs["-datadir"].c_str());
return EXIT_FAILURE;
}
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
try {
SelectParams(ChainNameFromCommandLine());