Check for datadir after the config files were read #13621

pull Flowdalic wants to merge 7 commits into bitcoin:master from Flowdalic:init-swap-datadir-readconf changing 5 files +27 −33
  1. Flowdalic commented at 6:34 am on July 10, 2018: contributor

    If we first check for datadir existence and then read the config file we bail out in situations where the default datadir is invalid, e.g. because of an non-existing HOME, but the datadir specified in config files is valid. We should not do that, as the user may specified a valid datadir in the config file and expects the setting to take effect.

    See for example #12255 (comment) where users hit this.

  2. fanquake added the label Refactoring on Jul 10, 2018
  3. fanquake renamed this:
    Check for datadir after the config files where read
    Check for datadir after the config files were read
    on Jul 10, 2018
  4. Flowdalic force-pushed on Jul 10, 2018
  5. Flowdalic force-pushed on Jul 10, 2018
  6. MarcoFalke added the label Utils/log/libs on Jul 10, 2018
  7. MarcoFalke removed the label Refactoring on Jul 10, 2018
  8. MarcoFalke commented at 4:05 pm on July 11, 2018: member
    Doesn’t the location of the default config file depend on the datadir?
  9. Flowdalic commented at 5:37 pm on July 11, 2018: contributor

    Doesn’t the location of the default config file depend on the datadir?

    Yes, BITCOIN_CONF_FILENAME, which is set to bitcoin.conf is feed into AbsPathForConfigVal() which uses the datadir setting. However, if no datadir is explicitly set it defaults to “”. I think that this means that bitcoin.conf is opened relative to the processe’s working directory.

    It appears that you have a specific problem in mind, which I don’t see. Care to elaborate?

  10. MarcoFalke commented at 6:41 pm on July 11, 2018: member
  11. Flowdalic commented at 5:54 am on July 12, 2018: contributor
    Right, the check can get probably removed.
  12. DrahtBot commented at 4:17 pm on July 17, 2018: member
    • #14409 (utils and libraries: Make ‘blocksdir’ always net specific by hebasto)
    • #14324 (qa: Run more tests with wallet disabled by MarcoFalke)
    • #13878 (utils: Add fstream wrapper to allow to pass unicode filename on Windows by ken2812221)
    • #13746 (-masterdatadir for datadir bootstrapping by kallewoof)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  13. DrahtBot added the label Needs rebase on Jul 18, 2018
  14. Flowdalic force-pushed on Jul 19, 2018
  15. Flowdalic force-pushed on Jul 19, 2018
  16. Flowdalic force-pushed on Jul 19, 2018
  17. Flowdalic force-pushed on Jul 19, 2018
  18. Flowdalic force-pushed on Jul 19, 2018
  19. Flowdalic force-pushed on Jul 19, 2018
  20. Do not create datadir when calling GetConfigFile
    As the real datadir may be set in the configuration file, this would
    case the default datadir to get created.
    dd906c12dc
  21. Do not fallback to empy path in GetDataDir()
    If datadir is not a directory, do not fallback to empty path as this would shadow the original path set in the config file. Consider
    
        bitcoin.conf:
        datadir=/does/not/exist
    
    and bitcoind started with "-conf=bitcoin.conf", which would previusly yield
    
        Error: Specified data directory "" does not exist.
    
    when it should state
    
        Error: Specified data directory "/does/not/exist" does not exist.
    1366577c5d
  22. Check for datadir after the config files were read
    If we first check for datadir existence and then read the config file
    we bail out in situations where the default datadir is invalid,
    e.g. because of an non-existing HOME, but the datadir specified in
    config files is valid. We should not do that, as the user specified a
    valid datadir and expects the setting to take effect.
    
    Also remove datadir check in ReadConfigFiles() which now became
    superfluous: We check for the datadir in AppInit() already, there is
    no need to check also in ReadConfigFiles().
    
    Furthermore re-enable the disabled tests in feature_config_args.py,
    which where disabled in fabe28a0cdc ("qa: Temporarily disable test
    that reads the default datadir location"), as those tests do not touch
    "$HOME/.bitcoin" any more.
    c6f01cb45e
  23. Show the datadir that was checked in error message b6a43dfc5b
  24. Flowdalic force-pushed on Jul 19, 2018
  25. Flowdalic commented at 7:43 pm on July 19, 2018: contributor

    Rebased. Also fixed the cause and re-enabled the tests which were disabled in #13687 with fabe28a0cdcfa13e0e595a0905e3642a960d3077.

    I had a hard time working on the argument and configuration file parsing code. It is a little bit spagettish and some parts are messy.

    I used default argument values in order to optionally change GetDataDir() to not create the data directory, which, I assumed, made the change less intrusive. But I am happy to change it towards a GetDataDir() / GetDataDirAndCreateIfNecessary(). I am undecied which of those two approaches would be better.

  26. DrahtBot removed the label Needs rebase on Jul 20, 2018
  27. in src/bitcoin-cli.cpp:128 in b6a43dfc5b outdated
    127-    }
    128     if (!gArgs.ReadConfigFiles(error, true)) {
    129         fprintf(stderr, "Error reading configuration file: %s\n", error.c_str());
    130         return EXIT_FAILURE;
    131     }
    132+    if (!fs::is_directory(GetDataDir(false))) {
    


    AtsukiTak commented at 5:15 pm on July 20, 2018:
    It seems never fail unless user specify unpermitted path.

    Flowdalic commented at 12:37 pm on July 21, 2018:
    It fails if the specified path is not a directory. I think that is sensible and was already previous behavior. Or do have a specific change request?

    AtsukiTak commented at 6:33 pm on July 21, 2018:

    If I specify a file, boost::filesystem::create_directory throw an error. If I specify a non-exist path, a new directory is created and no error happens.

    I think you just missed second argument; GetDataDir(false, false) might be what you want.


    AtsukiTak commented at 6:43 pm on July 21, 2018:
    Sorry for my poor English. Please feel free to ask me if my English is not clear.
  28. AtsukiTak commented at 5:28 pm on July 20, 2018: contributor

    Nice work :) But this PR seems to contains lots of changes for me such as

    • Check for datadir after the config files were read
    • Create directory if user specify non exist directory
    • Do not fallback to empy path in GetDataDir()

    I think you should leave only first one, and move rests to another PR, and then discuss about them.

  29. Flowdalic commented at 12:40 pm on July 21, 2018: contributor

    I think you should leave only first one

    Well, those commits depend on each other: For example I wouldn’t be able to re-enable the relevant tests of “Check for datadir after the config files were read” without the previous commits.

    I don’t feel like that this patch series is worth splitting up, as it is pretty small, but I am happy create single PRs for each commit one after another, if there is a consensus that this would be favorable.

  30. AtsukiTak commented at 6:43 pm on July 21, 2018: contributor

    I don’t feel like that this patch series is worth splitting up, as it is pretty small

    I see. So please don’t care about that. That was just newbie’s nonsense comment.

  31. DrahtBot added the label Needs rebase on Jul 31, 2018
  32. Merge branch 'master' into init-swap-datadir-readconf e8ca79df92
  33. DrahtBot removed the label Needs rebase on Aug 3, 2018
  34. Merge branch 'master' into init-swap-datadir-readconf bbd458c961
  35. leishman commented at 11:11 pm on August 24, 2018: contributor

    I don’t think our PRs conflict, but just wanted to make you aware of a minor change I’m putting in the logging behavior: #14057

    I’m also working on logic to create a bitcoin.conf.example file: #13761

  36. Merge remote-tracking branch 'origin/master' into init-swap-datadir-readconf 0053ea23d8
  37. Flowdalic commented at 11:10 am on September 7, 2018: contributor
    Pinging @MarcoFalke since this PR re-enables tests he disabled in fabe28a0cdcfa13e0e595a0905e3642a960d3077 (#13687). Would be great to hear your thoughts on this.
  38. MarcoFalke commented at 12:16 pm on September 7, 2018: member

    I haven’t looked at the most recent code, but I still think that the location of the default config file depends on the datadir? See https://dev.visucore.com/bitcoin/doxygen/class_args_manager.html#aec848fd54ace0df3df48dac446feb7d2 which calls GetDataDir.

    So you are changing how and what config files are read. Not sure if we want this behavior change without discussion first.

  39. MarcoFalke commented at 12:17 pm on September 7, 2018: member

    Also, you modified how bitcoind and bitcoin-cli work, but not the gui. Wouldn’t that lead to issues when the gui is used as rpc server via the bitcoin-cli?

    So if you really want to go ahead with these changes, they need tests that fail on master but pass with your fixes for bitcoind as well as the bitcoin-qt and bitcoin-cli.

  40. DrahtBot added the label Needs rebase on Oct 8, 2018
  41. DrahtBot commented at 6:07 am on October 8, 2018: member
  42. fanquake added the label Up for grabs on Jan 5, 2019
  43. fanquake commented at 6:06 am on January 5, 2019: member
    Closing “up for grabs”.
  44. fanquake closed this on Jan 5, 2019

  45. MarcoFalke referenced this in commit 83112db129 on Aug 19, 2019
  46. sidhujag referenced this in commit 894dd2f309 on Aug 19, 2019
  47. laanwj removed the label Needs rebase on Oct 24, 2019
  48. DrahtBot locked this on Dec 16, 2021

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-07-05 19:13 UTC

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