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 bitcoin/bitcoin#24257.
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 bitcoin/bitcoin#24257.
May I ask why you've added the sub directory /wallets ? While bitcoind and bitcoin-cli now runs fine without -datadir option (following my symbolic link), wallets are not found anymore because of that change.
2022-02-05T01:25:45Z Warning: Skipping -wallet path that doesn't exist. Failed to load database path '/home/me/.bitcoin/wallets/watching'. Path does not exist.
Warning: Skipping -wallet path that doesn't exist. Failed to load database path '/home/me/.bitcoin/wallets/watching'. Path does not exist.
Note that the sub directory /wallets was properly created
~/btc-things/bitcoin$ ll /home/me/.bitcoin/wallets/
total 4
drwxrwxrwx 1 root root 0 Feb 5 10:24 ./
drwxrwxrwx 1 root root 4096 Feb 5 10:26 ../
If you create the /wallets directory all the time, it will break current setups which don't use it. Now of course I could just move my wallet folder into the /wallets sub-directory and it would work fine, but that's probably not the way to go.
See here the wallet directory loading logic https://github.com/bitcoin/bitcoin/blob/master/src/wallet/walletutil.cpp#L25
@hebasto How about something like this instead? https://github.com/bitcoin/bitcoin/pull/24267
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
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.
Compiled with some libstdc++ versions (e.g., on Ubuntu 20.04)
std::filesystem:::create_directories() call fails to handle symbol links
properly.
Updated 94fe141d207999483d54b73a6318cc12fb853b46 -> b9c113af754540341d9529532fbadb7525168102 (pr24266.01 -> pr24266.02, diff):
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:
lrwxrwxrwx 1 me me 27 Feb 6 17:05 /home/me/.bitcoin -> /home/me/.bitcoindatadir/
lrwxrwxrwx 1 me me 31 Feb 6 17:04 /home/me/.bitcoindatadir -> /home/me/Documents/.bitcoin//
442 | @@ -443,14 +443,18 @@ const fs::path& ArgsManager::GetDataDir(bool net_specific) const 443 | } else { 444 | path = GetDefaultDataDir(); 445 | } 446 | - if (net_specific) 447 | - path /= fs::PathFromString(BaseParams().DataDir()); 448 | 449 | - if (fs::create_directories(path)) { 450 | - // This is the first run, create wallets subdirectory too
why is this comment removed?
Code if (!fs::exists(path)) { fs::create_directories(path / "wallets"); } expresses the same idea, therefore, the removed comment is redundant.
In commit "util: Avoid buggy std::filesystem:::create_directories() call" (b9c113af754540341d9529532fbadb7525168102)
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.
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.
457 | + if (!fs::exists(path)) { 458 | + fs::create_directories(path / "wallets"); 459 | + } 460 | + } 461 | + 462 | path = StripRedundantLastElementsOfPath(path);
In commit "util: Avoid buggy std::filesystem:::create_directories() call" (b9c113af754540341d9529532fbadb7525168102)
Could actually drop this line now. It won't do anything anymore because of the the new !empty check added above. But keeping this line is also fine. It's harmless and #24265 removes it anyway.
Code review ACK b9c113af754540341d9529532fbadb7525168102. Nice simplification and fix
442 | @@ -443,14 +443,18 @@ const fs::path& ArgsManager::GetDataDir(bool net_specific) const 443 | } else { 444 | path = GetDefaultDataDir(); 445 | } 446 | - if (net_specific) 447 | - path /= fs::PathFromString(BaseParams().DataDir()); 448 | 449 | - if (fs::create_directories(path)) { 450 | - // This is the first run, create wallets subdirectory too 451 | + if (!fs::exists(path)) {
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?
On master (8afcc89a8f96692dd880b6102c9a85fac18b9021):
$ 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
Ah ok, looks like this is a side effect of reading the config file in the main datadir.
review ACK b9c113af754540341d9529532fbadb7525168102 🐬
<details><summary>Show signature</summary>
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-----
</details>
I run into a similar issue with the blocks directory. I think it would be better to define our own drop in replacement, say, fsbridge::create_directories and use it everywhere that fs::create_directories is, not work around this in every single place.
Milestone
23.0