Skip to content

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Feb 4, 2022

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.

@nymkappa
Copy link

nymkappa commented Feb 5, 2022

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

@nymkappa
Copy link

nymkappa commented Feb 5, 2022

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

@nymkappa
Copy link

nymkappa commented Feb 5, 2022

@hebasto How about something like this instead? #24267

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 5, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #24274 (Introduce GetFileArg and use it where possible by prusnak)
  • #24265 (Drop StripRedundantLastElementsOfPath() function by hebasto)
  • #23931 (create bitcoin.conf on first run with template by prayank23)

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.
@hebasto hebasto marked this pull request as ready for review February 5, 2022 16:40
@hebasto
Copy link
Member Author

hebasto commented Feb 5, 2022

Updated 94fe141 -> b9c113a (pr24266.01 -> pr24266.02, diff):

@nymkappa
Copy link

nymkappa commented Feb 6, 2022

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//

@fanquake fanquake added this to the 23.0 milestone Feb 6, 2022
@fanquake fanquake requested a review from ryanofsky February 6, 2022 08:15

if (fs::create_directories(path)) {
// This is the first run, create wallets subdirectory too
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this comment removed?

Copy link
Member Author

@hebasto hebasto Feb 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code if (!fs::exists(path)) { fs::create_directories(path / "wallets"); } expresses the same idea, therefore, the removed comment is redundant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ryanofsky

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.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK b9c113a. Nice simplification and fix

fs::create_directories(path / "wallets");
}
}

path = StripRedundantLastElementsOfPath(path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "util: Avoid buggy std::filesystem:::create_directories() call" (b9c113a)

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's harmless and #24265 removes it anyway.

Exactly :)


if (fs::create_directories(path)) {
// This is the first run, create wallets subdirectory too
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, looks like this is a side effect of reading the config file in the main datadir.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@maflcko maflcko merged commit 8edb041 into bitcoin:master Feb 8, 2022
@hebasto hebasto deleted the 220204-dirs branch February 8, 2022 16:50
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 9, 2022
…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
@laanwj
Copy link
Member

laanwj commented Feb 11, 2022

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.

laanwj added a commit to laanwj/bitcoin that referenced this pull request Feb 14, 2022
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.
laanwj added a commit to laanwj/bitcoin that referenced this pull request Feb 14, 2022
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.
laanwj added a commit to laanwj/bitcoin that referenced this pull request Feb 14, 2022
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.
laanwj added a commit to laanwj/bitcoin that referenced this pull request Feb 14, 2022
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.
laanwj added a commit to laanwj/bitcoin that referenced this pull request Feb 16, 2022
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.
laanwj added a commit to laanwj/bitcoin that referenced this pull request Feb 16, 2022
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.
laanwj added a commit to laanwj/bitcoin that referenced this pull request Feb 16, 2022
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.
hebasto pushed a commit to hebasto/bitcoin that referenced this pull request Feb 16, 2022
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.
laanwj added a commit to laanwj/bitcoin that referenced this pull request Feb 17, 2022
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.
fanquake added a commit that referenced this pull request Feb 17, 2022
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
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 18, 2022
…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
hmel pushed a commit to hmel/bitcoin that referenced this pull request Feb 20, 2022
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.
@bitcoin bitcoin locked and limited conversation to collaborators Feb 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bitcoind and bitcoin-cli does not supports symbolic link anymore
7 participants