args: Properly support -noconf

-noconf would previously lead to an ifstream "successfully" being opened to the ".bitcoin"-directory (not a file). (Guards against the general case of directories as configs are added in grandchild commit to this one).

Other users of AbsPathForConfigVal() in combination with negated args have been updated earlier in this PR ("args: Support -nopid" and "args: Support -norpccookiefile...").
This commit is contained in:
Hodlinator
2024-12-03 09:45:47 +01:00
parent 312ec64cc0
commit 483f0dacc4
3 changed files with 41 additions and 30 deletions

View File

@@ -17,6 +17,7 @@
#include <util/translation.h>
#include <algorithm>
#include <filesystem>
#include <string>
#include <vector>
@@ -122,10 +123,11 @@ bool StartLogging(const ArgsManager& args)
// Only log conf file usage message if conf file actually exists.
fs::path config_file_path = args.GetConfigFilePath();
if (fs::exists(config_file_path)) {
if (args.IsArgNegated("-conf")) {
LogInfo("Config file: <disabled>");
} else if (fs::exists(config_file_path)) {
LogPrintf("Config file: %s\n", fs::PathToString(config_file_path));
} else if (args.IsArgSet("-conf")) {
// Warn if no conf file exists at path provided by user
InitWarning(strprintf(_("The specified config file %s does not exist"), fs::PathToString(config_file_path)));
} else {
// Not categorizing as "Warning" because it's the default behavior