New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for datadir after the config files were read #13621
Conversation
6bcdbd3
to
94a038b
Compare
Doesn't the location of the default config file depend on the datadir? |
Yes, BITCOIN_CONF_FILENAME, which is set to It appears that you have a specific problem in mind, which I don't see. Care to elaborate? |
See https://dev.visucore.com/bitcoin/doxygen/class_args_manager.html#aec848fd54ace0df3df48dac446feb7d2 which calls |
Now the second if clause seems meaningless. Because it already checked in Lines 909 to 912 in 4a7e64f
|
Right, the check can get probably removed. |
Reviewers, this pull request conflicts with the following ones:
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. |
be2ba85
to
9b1987f
Compare
As the real datadir may be set in the configuration file, this would case the default datadir to get created.
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.
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 fabe28a ("qa: Temporarily disable test that reads the default datadir location"), as those tests do not touch "$HOME/.bitcoin" any more.
0717367
to
b6a43df
Compare
Rebased. Also fixed the cause and re-enabled the tests which were disabled in #13687 with fabe28a. 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. |
if (!gArgs.ReadConfigFiles(error, true)) { | ||
fprintf(stderr, "Error reading configuration file: %s\n", error.c_str()); | ||
return EXIT_FAILURE; | ||
} | ||
if (!fs::is_directory(GetDataDir(false))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems never fail unless user specify unpermitted path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for my poor English. Please feel free to ask me if my English is not clear.
Nice work :)
I think you should leave only first one, and move rests to another PR, and then discuss about them. |
I see. So please don't care about that. That was just newbie's nonsense comment. |
Pinging @MarcoFalke since this PR re-enables tests he disabled in fabe28a (#13687). Would be great to hear your thoughts on this. |
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 So you are changing how and what config files are read. Not sure if we want this behavior change without discussion first. |
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. |
Needs rebase |
Closing "up for grabs". |
ffea41f Enable all tests in feature_config_args.py (Hennadii Stepanov) 66f5c17 Use CheckDataDirOption() for code uniformity (Hennadii Stepanov) 7e33a18 Fix datadir handling in bitcoin-cli (Hennadii Stepanov) b28dada Fix datadir handling in bitcoin-qt (Hennadii Stepanov) 5082409 Fix datadir handling in bitcoind (Hennadii Stepanov) 740d41c Add CheckDataDirOption() function (Hennadii Stepanov) c1f3251 Return absolute path early in AbsPathForConfigVal (Hennadii Stepanov) Pull request description: Fix #15240, see: #15240 (comment) Fix #15745 Fix broken `feature_config_args.py` tests (disabled by MarcoFalke@fabe28a0cdcfa13e0e595a0905e3642a960d3077). All test are enabled now. This PR is alternative to #13621. User's `$HOME` directory is not touched unnecessarily now. ~To make reviewing easier only `bitcoind` code is modified (neither `bitcoin-cli` nor `bitcoin-qt`).~ Refs: - #15745 (comment) by **laanwj** - #16220 Top commit has no ACKs. Tree-SHA512: 4a4cda10e0b67c8f374da0c9567003d2b566d948e7f8550fe246868b5794c15010e88ea206009480b9cd2f737f310a15e984f920730448f99a895893bed351df
ffea41f Enable all tests in feature_config_args.py (Hennadii Stepanov) 66f5c17 Use CheckDataDirOption() for code uniformity (Hennadii Stepanov) 7e33a18 Fix datadir handling in bitcoin-cli (Hennadii Stepanov) b28dada Fix datadir handling in bitcoin-qt (Hennadii Stepanov) 5082409 Fix datadir handling in bitcoind (Hennadii Stepanov) 740d41c Add CheckDataDirOption() function (Hennadii Stepanov) c1f3251 Return absolute path early in AbsPathForConfigVal (Hennadii Stepanov) Pull request description: Fix bitcoin#15240, see: bitcoin#15240 (comment) Fix bitcoin#15745 Fix broken `feature_config_args.py` tests (disabled by MarcoFalke@fabe28a0cdcfa13e0e595a0905e3642a960d3077). All test are enabled now. This PR is alternative to bitcoin#13621. User's `$HOME` directory is not touched unnecessarily now. ~To make reviewing easier only `bitcoind` code is modified (neither `bitcoin-cli` nor `bitcoin-qt`).~ Refs: - bitcoin#15745 (comment) by **laanwj** - bitcoin#16220 Top commit has no ACKs. Tree-SHA512: 4a4cda10e0b67c8f374da0c9567003d2b566d948e7f8550fe246868b5794c15010e88ea206009480b9cd2f737f310a15e984f920730448f99a895893bed351df
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.