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. Flowdalic cross-referenced this on Jul 10, 2018 from issue Update bitcoin.service to conform to init.md by dongcarl
  3. fanquake added the label Refactoring on Jul 10, 2018
  4. 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
  5. Flowdalic force-pushed on Jul 10, 2018
  6. Flowdalic force-pushed on Jul 10, 2018
  7. MarcoFalke added the label Utils/log/libs on Jul 10, 2018
  8. MarcoFalke removed the label Refactoring on Jul 10, 2018
  9. MarcoFalke commented at 4:05 PM on July 11, 2018: member

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

  10. 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?

  11. MarcoFalke commented at 6:41 PM on July 11, 2018: member
  12. Flowdalic commented at 5:54 AM on July 12, 2018: contributor

    Right, the check can get probably removed.

  13. DrahtBot cross-referenced this on Jul 17, 2018 from issue travis: Check that ~/.bitcoin is never created by MarcoFalke
  14. DrahtBot commented at 4:17 PM on July 17, 2018: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->Reviewers, this pull request conflicts with the following ones:

    • #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.

  15. DrahtBot added the label Needs rebase on Jul 18, 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. Flowdalic force-pushed on Jul 19, 2018
  21. Flowdalic force-pushed on Jul 19, 2018
  22. 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
  23. 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
  24. 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
  25. Show the datadir that was checked in error message b6a43dfc5b
  26. Flowdalic force-pushed on Jul 19, 2018
  27. 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.

  28. DrahtBot removed the label Needs rebase on Jul 20, 2018
  29. 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.

  30. 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.

  31. 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.

  32. 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.

  33. DrahtBot cross-referenced this on Jul 22, 2018 from issue [bugfix] Fix encoding issue for Windows by ken2812221
  34. DrahtBot cross-referenced this on Jul 25, 2018 from issue [WIP] Full unicode support on Windows by ken2812221
  35. DrahtBot cross-referenced this on Jul 25, 2018 from issue -masterdatadir for datadir bootstrapping by kallewoof
  36. DrahtBot cross-referenced this on Jul 26, 2018 from issue Docs: Create default bitcoin.conf file on startup by leishman
  37. DrahtBot cross-referenced this on Jul 28, 2018 from issue [refactor] Fix the chainparamsbase -> util circular dependency by Empact
  38. DrahtBot cross-referenced this on Jul 28, 2018 from issue Test for Windows encoding issue by ken2812221
  39. DrahtBot cross-referenced this on Jul 30, 2018 from issue Ignore unknown config file options; warn instead of error by sipa
  40. DrahtBot added the label Needs rebase on Jul 31, 2018
  41. Merge branch 'master' into init-swap-datadir-readconf e8ca79df92
  42. DrahtBot removed the label Needs rebase on Aug 3, 2018
  43. DrahtBot cross-referenced this on Aug 4, 2018 from issue utils: Add fstream wrapper to allow to pass unicode filename on Windows by ken2812221
  44. Merge branch 'master' into init-swap-datadir-readconf bbd458c961
  45. 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

  46. Merge remote-tracking branch 'origin/master' into init-swap-datadir-readconf 0053ea23d8
  47. 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.

  48. 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.

  49. 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.

  50. DrahtBot cross-referenced this on Sep 26, 2018 from issue qa: Run more tests with wallet disabled by MarcoFalke
  51. DrahtBot cross-referenced this on Oct 5, 2018 from issue utils and libraries: Make 'blocksdir' always net specific by hebasto
  52. DrahtBot added the label Needs rebase on Oct 8, 2018
  53. DrahtBot commented at 6:07 AM on October 8, 2018: contributor

    <!--cf906140f33d8803c4a75a2196329ecb-->Needs rebase

  54. fanquake added the label Up for grabs on Jan 5, 2019
  55. fanquake commented at 6:06 AM on January 5, 2019: member

    Closing "up for grabs".

  56. fanquake closed this on Jan 5, 2019

  57. hebasto cross-referenced this on Apr 21, 2019 from issue Fix datadir handling by hebasto
  58. MarcoFalke referenced this in commit 83112db129 on Aug 19, 2019
  59. sidhujag referenced this in commit 894dd2f309 on Aug 19, 2019
  60. laanwj removed the label Needs rebase on Oct 24, 2019
  61. bitcoin 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: 2026-05-20 06:55 UTC