util: Avoid buggy std::filesystem:::create_directories() call#24266
util: Avoid buggy std::filesystem:::create_directories() call#24266maflcko merged 1 commit intobitcoin:masterfrom
Conversation
|
May I ask why you've added the sub directory Note that the sub directory |
|
If you create the See here the wallet directory loading logic https://github.com/bitcoin/bitcoin/blob/master/src/wallet/walletutil.cpp#L25 |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
Compiled with some libstdc++ versions (e.g., on Ubuntu 20.04) std::filesystem:::create_directories() call fails to handle symbol links properly.
|
Updated 94fe141 -> b9c113a (pr24266.01 -> pr24266.02, diff): |
Tested ACK. This fix is superior to #24267 as it keeps pre-20744 master branch behavior. Additional perk is that it allows to follow symbolik links with a multiple depth levels, for example this works fine with this PR: |
| path /= fs::PathFromString(BaseParams().DataDir()); | ||
|
|
||
| if (fs::create_directories(path)) { | ||
| // This is the first run, create wallets subdirectory too |
There was a problem hiding this comment.
Code if (!fs::exists(path)) { fs::create_directories(path / "wallets"); } expresses the same idea, therefore, the removed comment is redundant.
There was a problem hiding this comment.
In commit "util: Avoid buggy std::filesystem:::create_directories() call" (b9c113a)
This is a tangent, but it would be nice to avoid creating this wallets directory here in the future. This is done for the backward compatibility, so wallet startup code is able to set -walletdir=<datadir> instead of -walletdir=<datadir>/wallets later if this directory doesn't exist.
I think a better approach would be to always use -walletdir=<datadir>/wallets and use a wallets -> . symlink for compatibility instead. On startup, datadir code would not have to create any "wallets" subdirectory. Instead wallet startup code would look for a <datadir>/wallets directory or symlink and use it if it exists. Otherwise it would call wallet::ListDatabases(GetDataDir()), and if the list is empty create the <datadir>/wallets directory. If the list is nonempty, create a <datadir>/wallets -> . symlink.
There was a problem hiding this comment.
Agree. I was thinking about the same some time back and now. And I think it deserves its own PR, keeping this one focused on a workaround for buggy libc++ preserving the current behavior.
| } | ||
| } | ||
|
|
||
| path = StripRedundantLastElementsOfPath(path); |
There was a problem hiding this comment.
There was a problem hiding this comment.
It's harmless and #24265 removes it anyway.
Exactly :)
| path /= fs::PathFromString(BaseParams().DataDir()); | ||
|
|
||
| if (fs::create_directories(path)) { | ||
| // This is the first run, create wallets subdirectory too |
There was a problem hiding this comment.
In commit "util: Avoid buggy std::filesystem:::create_directories() call" (b9c113a)
This is a tangent, but it would be nice to avoid creating this wallets directory here in the future. This is done for the backward compatibility, so wallet startup code is able to set -walletdir=<datadir> instead of -walletdir=<datadir>/wallets later if this directory doesn't exist.
I think a better approach would be to always use -walletdir=<datadir>/wallets and use a wallets -> . symlink for compatibility instead. On startup, datadir code would not have to create any "wallets" subdirectory. Instead wallet startup code would look for a <datadir>/wallets directory or symlink and use it if it exists. Otherwise it would call wallet::ListDatabases(GetDataDir()), and if the list is empty create the <datadir>/wallets directory. If the list is nonempty, create a <datadir>/wallets -> . symlink.
|
|
||
| if (fs::create_directories(path)) { | ||
| // This is the first run, create wallets subdirectory too | ||
| if (!fs::exists(path)) { |
There was a problem hiding this comment.
Looks like this is also adding a new feature?
Previously, when a test chain was used on the first run, it wouldn't create the wallets dir in the root datadir (main). Now it does?
There was a problem hiding this comment.
On master (8afcc89):
$ rm -rf ~/.bitcoin
$ ./src/bitcoind -testnet
$ find ~/.bitcoin -type d
/home/hebasto/.bitcoin
/home/hebasto/.bitcoin/wallets
/home/hebasto/.bitcoin/testnet3
/home/hebasto/.bitcoin/testnet3/wallets
/home/hebasto/.bitcoin/testnet3/chainstate
/home/hebasto/.bitcoin/testnet3/blocks
/home/hebasto/.bitcoin/testnet3/blocks/index
There was a problem hiding this comment.
Ah ok, looks like this is a side effect of reading the config file in the main datadir.
maflcko
left a comment
There was a problem hiding this comment.
review ACK b9c113a 🐬
Show signature
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
review ACK b9c113af754540341d9529532fbadb7525168102 🐬
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjjYQv/cXNDjyxMuXXzCYEPC7+MwDfQfxws/Xyqbj6nJS4ke7gzmzBfn9VW+pp8
CABVuHSJuux5ElxAJcVWq1ODdlt/qUPeN8Ili7K3i03DvxtlDKyRUfAXneXoNysE
LGVkWd4U2cq4zwidgpjD5yo+QFeXVe9qg00YFxsqevmWQ73o2hJMhJxdAyfVdz8N
QuMZMthT1jvdoBP9ROq+2qNZob4ZBizHWsoHGCOqmyhFJokgXXfUMHZD4TVT321A
zc7M6+daVWH8UTNHxuXw8V9cLDbAMHJhKDj+Y4dOLwFjbtXuD13ZJI1VG5KC4VZo
dN36XSOCsjqpaoNvwQ5dKs28QDNHtAUXw91Dz9vCsYxulY7GrTUtkDxmdGsCjnWX
EcNYGnD+6JagiR9101WG0RbgeOyRnNk12gOhcURX8jtACgCcW6CzQyhvfUtY9Nhj
KBnSJYOIOstzhkDq7BBnw41+3R25ezZmaI8yQs+H0lOw04eTtxMiZYmi0Chg9WwY
LnF0vBuD
=+A1J
-----END PGP SIGNATURE-----
…tories() call b9c113a util: Avoid buggy std::filesystem:::create_directories() call (Hennadii Stepanov) Pull request description: Compiled with some libstdc++ versions (e.g., on Ubuntu 20.04) [`std::filesystem:::create_directories()`](https://en.cppreference.com/w/cpp/filesystem/create_directory) call [fails](bitcoin#24257 (comment)) to handle symbol links properly. No behavior change in comparison to the [pre-20744](bitcoin@c194293) master branch. Fixes bitcoin#24257. ACKs for top commit: ryanofsky: Code review ACK b9c113a. Nice simplification and fix MarcoFalke: review ACK b9c113a 🐬 Tree-SHA512: 79d940cfc1f68d9b0548fb2ab005e90850b54ac0fb3bb2940afd632d56288d92687579a3176bac3fd0ea3d2dae71e26444f8f7bdb87862414c12866ae5e857c4
|
I run into a similar issue with the |
Work around libstdc++ issue [PR101510] with create_directories where the leaf already exists as a symlink. Fixes bitcoin#24257, introduced by the switch to `std::filesystem`. It is meant to be more thorough than bitcoin#24266, which only worked around one instance of the problem. The issue was fixed upstream in https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=124eaa50e0a34f5f89572c1aa812c50979da58fc, but unfortunately we'll have to carry a fix for it for a while. This introduces a function `fs::create_directories` which wraps `std::filesystem::create_directories`. This allows easiliy reverting the workaround when it is no longer necessary.
Work around libstdc++ issue [PR101510] with create_directories where the leaf already exists as a symlink. Fixes bitcoin#24257, introduced by the switch to `std::filesystem`. It is meant to be more thorough than bitcoin#24266, which only worked around one instance of the problem. The issue was fixed upstream in https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=124eaa50e0a34f5f89572c1aa812c50979da58fc, but unfortunately we'll have to carry a fix for it for a while. This introduces a function `fs::create_directories` which wraps `std::filesystem::create_directories`. This allows easiliy reverting the workaround when it is no longer necessary.
b223c3c test: Add functional test for symlinked blocks directory (laanwj) ddb75c2 test: Add fs_tests/create_directories unit test (Hennadii Stepanov) 1f46b6e util: Work around libstdc++ create_directories issue (laanwj) Pull request description: Work around libstdc++ issue [PR101510] with create_directories where the leaf already exists as a symlink. Fixes #24257, introduced by the switch to `std::filesystem`. It is meant to be more thorough than #24266, which worked around one instance of the problem. The issue was [fixed upstream](https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=124eaa50e0a34f5f89572c1aa812c50979da58fc), but unfortunately we'll have to carry a fix for it for a while. This introduces a function `fs::create_directories` which wraps `std::filesystem::create_directories`. This allows easiliy reverting the workaround when it is no longer necessary. ACKs for top commit: jonatack: re-ACK b223c3c per `git range-diff df08250 67019cd b223c3c` hebasto: re-ACK b223c3c w0xlt: re-ACK b223c3c vasild: ACK b223c3c Tree-SHA512: 028321717c8b10d16185c3711b35da6b05fb7aa31cee1c8c7e754e92bf5a0b02719a3785cd0f6f8bf052b3bd759f644af212320672baabc9e44e0b93ba464abc
…ssue b223c3c test: Add functional test for symlinked blocks directory (laanwj) ddb75c2 test: Add fs_tests/create_directories unit test (Hennadii Stepanov) 1f46b6e util: Work around libstdc++ create_directories issue (laanwj) Pull request description: Work around libstdc++ issue [PR101510] with create_directories where the leaf already exists as a symlink. Fixes bitcoin#24257, introduced by the switch to `std::filesystem`. It is meant to be more thorough than bitcoin#24266, which worked around one instance of the problem. The issue was [fixed upstream](https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=124eaa50e0a34f5f89572c1aa812c50979da58fc), but unfortunately we'll have to carry a fix for it for a while. This introduces a function `fs::create_directories` which wraps `std::filesystem::create_directories`. This allows easiliy reverting the workaround when it is no longer necessary. ACKs for top commit: jonatack: re-ACK b223c3c per `git range-diff df08250 67019cd b223c3c` hebasto: re-ACK b223c3c w0xlt: re-ACK b223c3c vasild: ACK b223c3c Tree-SHA512: 028321717c8b10d16185c3711b35da6b05fb7aa31cee1c8c7e754e92bf5a0b02719a3785cd0f6f8bf052b3bd759f644af212320672baabc9e44e0b93ba464abc
Work around libstdc++ issue [PR101510] with create_directories where the leaf already exists as a symlink. Fixes bitcoin#24257, introduced by the switch to `std::filesystem`. It is meant to be more thorough than bitcoin#24266, which only worked around one instance of the problem. The issue was fixed upstream in https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=124eaa50e0a34f5f89572c1aa812c50979da58fc, but unfortunately we'll have to carry a fix for it for a while. This introduces a function `fs::create_directories` which wraps `std::filesystem::create_directories`. This allows easiliy reverting the workaround when it is no longer necessary.
Compiled with some libstdc++ versions (e.g., on Ubuntu 20.04)
std::filesystem:::create_directories()call fails to handle symbol links properly.No behavior change in comparison to the pre-20744 master branch.
Fixes #24257.