Repository: bitcoin/bitcoin
File: src/common/init.cpp (C++)

Code before:
        // Create datadir if it does not exist.
        const auto base_path{args.GetDataDirBase()};
        if (!fs::exists(base_path)) {
            // When creating a *new* datadir, also create a "wallets" subdirectory,
            // whether or not the wallet is enabled now, so if the wallet is enabled
            // in the future, it will use the "wallets" subdirectory for creating
            // and listing wallets, rather than the top-level directory where
            // wallets could be mixed up with other files. For backwards
            // compatibility, wallet code will use the "wallets" subdirectory only
            // if it already exists, but never create it itself. There is discussion
            // in https://github.com/bitcoin/bitcoin/issues/16220 about ways to
            // change wallet code so it would no longer be necessary to create
            // "wallets" subdirectories here.
            fs::create_directories(base_path / "wallets");
        }
        const auto net_path{args.GetDataDirNet()};
        if (!fs::exists(net_path)) {
            fs::create_directories(net_path / "wallets");
        }

        // Show an error or warning if there is a bitcoin.conf file in the
        // datadir that is being ignored.
        const fs::path base_config_path = base_path / BITCOIN_CONF_FILENAME;
        if (fs::exists(base_config_path) && !fs::equivalent(orig_config_path, base_config_path)) {
            const std::string cli_config_path = args.GetArg("-conf", "");
            const std::string config_source = cli_config_path.empty()
                ? strprintf("data directory %s", fs::quoted(fs::PathToString(orig_datadir_path)))
                : strprintf("command line argument %s", fs::quoted("-conf=" + cli_config_path));
            const std::string error = strprintf(
                "Data directory %1$s contains a %2$s file which is ignored, because a different configuration file "
                "%3$s from %4$s is being used instead. Possible ways to address this would be to:\n"
                "- Delete or rename the %2$s file in data directory %1$s.\n"
                "- Change datadir= or conf= options to specify one configuration file, not two, and use "
                "includeconf= to include any other configuration files.\n"
                "- Set allowignoredconf=1 option to treat this condition as a warning, not an error.",
                fs::quoted(fs::PathToString(base_path)),
                fs::quoted(BITCOIN_CONF_FILENAME),
                fs::quoted(fs::PathToString(orig_config_path)),
                config_source);
            if (args.GetBoolArg("-allowignoredconf", false)) {
                LogPrintf("Warning: %s\n", error);
            } else {
                return ConfigError{ConfigStatus::FAILED, Untranslated(error)};
            }
        }

        // Create settings.json if -nosettings was not specified.
        if (args.GetSettingsPath()) {
            std::vector<std::string> details;
            if (!args.ReadSettingsFile(&details)) {
                const bilingual_str& message = _("Settings file could not be read");

Review comment (bug):
In commit "args: Properly support -noconf" (2ac863bdf974d7b4b4e8314876d02270400b6240)

I'm still not sure why this is a useful warning. There would seem to be little reason to specify `-noconf` unless you are trying to ignore a config file, so why should you be warned if a file you were trying to ignore exists?  If anything, you might expect a warning in the opposite case, when a file you specified an option to ignore does *not* exist. Both warnings seem excessive to me and and I think the approach from 3a856c86685a5ab6f3cb78b17cb52cbb1b9ad95b just adding `orig_config_path.empty()` to this code so it functions with `-noconf` would make the most sense.

If you do see value in logging this information though, I think it should use LogInfo or LogDebug, instead of LogWarning.

Code after:
        // Create datadir if it does not exist.
        const auto base_path{args.GetDataDirBase()};
        if (!fs::exists(base_path)) {
            // When creating a *new* datadir, also create a "wallets" subdirectory,
            // whether or not the wallet is enabled now, so if the wallet is enabled
            // in the future, it will use the "wallets" subdirectory for creating
            // and listing wallets, rather than the top-level directory where
            // wallets could be mixed up with other files. For backwards
            // compatibility, wallet code will use the "wallets" subdirectory only
            // if it already exists, but never create it itself. There is discussion
            // in https://github.com/bitcoin/bitcoin/issues/16220 about ways to
            // change wallet code so it would no longer be necessary to create
            // "wallets" subdirectories here.
            fs::create_directories(base_path / "wallets");
        }
        const auto net_path{args.GetDataDirNet()};
        if (!fs::exists(net_path)) {
            fs::create_directories(net_path / "wallets");
        }

        // Show an error or warn/log if there is a bitcoin.conf file in the
        // datadir that is being ignored.
        const fs::path base_config_path = base_path / BITCOIN_CONF_FILENAME;
        if (fs::exists(base_config_path)) {
            if (orig_config_path.empty()) {
                LogInfo(
                    "Data directory %s contains a %s file which is explicitly ignored using -noconf.",
                    fs::quoted(fs::PathToString(base_path)),
                    fs::quoted(BITCOIN_CONF_FILENAME));
            } else if (!fs::equivalent(orig_config_path, base_config_path)) {
                const std::string cli_config_path = args.GetArg("-conf", "");
                const std::string config_source = cli_config_path.empty()
                    ? strprintf("data directory %s", fs::quoted(fs::PathToString(orig_datadir_path)))
                    : strprintf("command line argument %s", fs::quoted("-conf=" + cli_config_path));
                std::string error = strprintf(
                    "Data directory %1$s contains a %2$s file which is ignored, because a different configuration file "
                    "%3$s from %4$s is being used instead. Possible ways to address this would be to:\n"
                    "- Delete or rename the %2$s file in data directory %1$s.\n"
                    "- Change datadir= or conf= options to specify one configuration file, not two, and use "
                    "includeconf= to include any other configuration files.",
                    fs::quoted(fs::PathToString(base_path)),
                    fs::quoted(BITCOIN_CONF_FILENAME),
                    fs::quoted(fs::PathToString(orig_config_path)),
                    config_source);
                if (args.GetBoolArg("-allowignoredconf", false)) {
                    LogWarning("%s", error);
                } else {
                    error += "\n- Set allowignoredconf=1 option to treat this condition as a warning, not an error.";
                    return ConfigError{ConfigStatus::FAILED, Untranslated(error)};
                }
            }