Relative paths named in the -conf parameter reset when parsing datadir in named config #19990

issue brianddk openend this issue on September 22, 2020
  1. brianddk commented at 3:11 am on September 22, 2020: contributor

    When naming a configuration file using a relative path using the -conf command line parameter, the configuration parser will present an error if the datadir option is listed in the named configuration file. The configuration parser will expect the named config file in both the default datadir and the named datadir.

    For example. Given the config file named usb.conf with the contents:

    0# Bitcoin Config file: %APPDATA%\Bitcoin\usb.conf
    1datadir=D:\Bitcoin
    

    And calling bitcoin with the following "%PROGRAMFILES%\Bitcoin\Bitcoin-qt.exe" -conf=usb.conf the config parser will present an error if D:\Bitcoin\usb.conf does not exist. Clearly it has found and parsed %APPDATA%\Bitcoin\usb.conf but yet it still needs to parse D:\Bitcoin\usb.conf

    Expected behavior

    Command line arguments should trump config file arguments. So since -datadir is not specified on the command line, the location for the named config file should correctly resolve to %APPDATA%\Bitcoin\usb.conf without further dependencies on D:\Bitcoin\usb.conf. Once the initial path location is resolved, it should not be reevaluated. This is understandably a “special case”. Normally relative paths are resolved from datadir, but the -conf parameter is already special in the sense that is not supported in the config file parsing, so should not be influenced by what is parsed from the config file.

    Actual behavior

    The config parser throws an error if the config file does not exist both in the default datadir and the named datadir

    issue

    Note, as a workaround, providing the full path to the config file mutes the error. This is only related to how relative paths are interpreted.

    To reproduce

    Completely reproducible

    System information

    • Windows 10.0.18363 Build 18363
    • Precompiled 0.20.1 Windows x64 binaries landed from installer downloaded from bitcoin.org
    • Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz, 3001 Mhz, 4 Core(s), 4 Logical Processor(s)
    • Disk0: WDC WD10EZEX
    • Disk1: Generic USB mounted SSD
  2. brianddk added the label Bug on Sep 22, 2020
  3. ryanofsky commented at 2:55 pm on September 22, 2020: contributor

    Thanks for the clear bug report! Agree this behavior is not good. I tend to think a simpler fix would be to just disallow relative -conf paths entirely, making specifying any relative -conf path an error, instead of interpreting relative -conf paths differently depending on the source of the -conf value (command line vs config file vs settings.json).

    Another benefit of making specifying a relative -conf paths an error instead of changing the interpretation would be that that if someone is relying on current behavior and upgrades they can encounter an explicit error instead of a subtly broken configuration.

    Maybe this is too extreme though? @brianddk maybe you had a use-case for specifying a relative path instead of an absolute path?

    A compromise option instead of forbidding relative -conf paths outright, or interpretting relative -conf paths differently depending on where they are specified might be to only forbid relative -conf paths when a -datadir value is specified.

  4. brianddk commented at 0:48 am on September 23, 2020: contributor

    @ryanofsky I think relative paths within the config file should probably stay, but agree that relative paths in a named -conf parameter could be nixed. I would think the more common answer is that relative paths in command-line parameters would be assumed relative to $PWD, which seems to be what most of the unix tool do. This would be a move more to “convention” as opposed to fixing some weird use case.

    Relative paths within a config file have no real “convention” to hold to, so I see no need to change that behavior, assuming the two behaviors can be divorced from each other.

  5. pinheadmz commented at 2:52 pm on March 27, 2023: member

    I tried to reproduce on macOS on master @ 20bd591345, there is still a warning (examples below). This issue is solved by #27303!

    Absolute -conf path

    conf file (/private/tmp/cdata/bitcoin.conf):

    0datadir=/tmp/tmp2
    

    command:

    0bitcoind -conf=/private/tmp/cdata/bitcoin.conf
    

    output:

    0...
    12023-03-27T14:40:02Z Default data directory /Users/matthewzipkin/Library/Application Support/Bitcoin
    22023-03-27T14:40:02Z Using data directory /tmp/tmp2
    32023-03-27T14:40:02Z Config file: /private/tmp/cdata/bitcoin.conf
    42023-03-27T14:40:02Z Config file arg: datadir="/tmp/tmp2"
    52023-03-27T14:40:02Z Command-line arg: conf="/private/tmp/cdata/bitcoin.conf"
    6...
    

    behavior: bitcoind starts with no errors, uses /tmp/tmp2 as datadir and blocksdir.

    Relative -conf path

    conf file (/Users/matthewzipkin/Library/Application\ Support/Bitcoin/relative/bitcoin.conf):

    0datadir=/tmp/tmp2
    

    command:

    0bitcoind -conf=relative/bitcoin.conf
    

    output:

    0...
    12023-03-27T14:46:11Z Default data directory /Users/matthewzipkin/Library/Application Support/Bitcoin
    22023-03-27T14:46:11Z Using data directory /tmp/tmp2
    32023-03-27T14:46:11Z Warning: The specified config file /tmp/tmp2/relative/bitcoin.conf does not exist
    4Warning: The specified config file /tmp/tmp2/relative/bitcoin.conf does not exist
    52023-03-27T14:46:11Z Config file arg: datadir="/tmp/tmp2"
    62023-03-27T14:46:11Z Command-line arg: conf="relative/bitcoin.conf"
    7...
    

    behavior: bitcoind starts with no errors, uses /tmp/tmp2 as datadir and blocksdir.

  6. ryanofsky commented at 6:28 pm on March 27, 2023: contributor

    This issue is solved by #27303

    Good find, agree it solves originally reported issue.

    It might still be a little confusing that relative -conf paths would be allowed on the command line, and wouldn’t be interpreted relative to the current working directory or to the final datadir location, but relative to the default datadir location. But arguably there are uses cases for this behavior (like putting multiple 1.conf, 2.conf files in the default datadir location, and having them specify different options and different final datadir= paths internally, and so you can conveniently pass -conf=1.conf or -conf=2.conf options on the command line that will work regardless of the current working directory).

  7. willcl-ark commented at 1:37 pm on April 26, 2023: member
    Will this issue be closed by #27302 ?
  8. ryanofsky commented at 2:31 pm on April 26, 2023: contributor

    Will this issue be closed by #27302 ?

    Yes specifically it is fixed by the third commit 0319de5cbedd1a8f8766cfec61151c58b3fb27ef from #27302. That commit changes the ArgsManager::GetConfigFilePath definition so the “The specified config file %s does not exist” warning is no longer triggered:

    https://github.com/bitcoin/bitcoin/blob/91ccb62faab21b2b52b089cc04f3a5c1bf6989cc/src/init/common.cpp#L125-L130

  9. pinheadmz commented at 7:15 pm on May 31, 2023: member
  10. pinheadmz closed this on May 31, 2023

  11. bitcoin locked this on May 30, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-21 18:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me