-
Notifications
You must be signed in to change notification settings - Fork 37.7k
wallet: Fix issues when walletdir
is root directory
#21944
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
Conversation
Welp, I did crazy thing and launched
Created wallet, and then listed:
Interesting to see Anyhow, issue is the same on Linux, and this PR did fix that too:
|
Yes it recursively iterates path mentioned. How much time did this take?
Interesting. Thanks for testing this on Linux. I will change name, description, commit message and comment after testing few more things. Although I think it's less likely someone will save wallet in root on Linux. But it's normal to save different folders in root of different partitions on Windows. |
walletdir
is root directory(Windows)walletdir
is root directory
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.
Not sure it's worth adding these cases considering #20744 unless we want to backport the fix.
src/wallet/db.cpp
Outdated
fs::path path = wallet_dir.string(); | ||
|
||
if (path == path.root_path()) { //If path is a 'root directory' for Windows | ||
path = it->path().string().substr(offset - 1); |
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.
nit, wrong indent
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
About 19s in a VM running on i7 laptop with SATA SSD. |
|
Definitely good to have a fix for this issue. Would welcome simplifying the PR though. I think the following would be a simpler short term fix than c5ee096: diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp
index cd49baeb786..993dd09b8b9 100644
--- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -12,7 +12,7 @@
std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
{
- const size_t offset = wallet_dir.string().size() + 1;
+ const size_t offset = wallet_dir.string().size() + (wallet_dir == wallet_dir.root_name() ? 0 : 1);
std::vector<fs::path> paths;
boost::system::error_code ec;
This:
In long term after we switch from boost (#20744) or update boost (#19667), a more robust fix also suggested #21501 (comment) would be: --- a/src/wallet/db.cpp
+++ b/src/wallet/db.cpp
@@ -12,7 +12,6 @@
std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
{
- const size_t offset = wallet_dir.string().size() + 1;
std::vector<fs::path> paths;
boost::system::error_code ec;
@@ -24,8 +23,7 @@ std::vector<fs::path> ListDatabases(const fs::path& wallet_dir)
try {
// Get wallet path relative to walletdir by removing walletdir from the wallet path.
- // This can be replaced by boost::filesystem::lexically_relative once boost is bumped to 1.60.
- const fs::path path = it->path().string().substr(offset);
+ const fs::path path = fs::lexically_relative(it->path(), wallet_dir);
if (it->status().type() == fs::directory_file &&
(IsBDBFile(BDBDataFile(it->path())) || IsSQLiteFile(SQLiteDataFile(it->path())))) { If we wanted to be really ambitious maybe we could write a unit test for the bug using subst |
+ Remove one character less from wallet path if root directory
Thanks for the review @ryanofsky Made changes in d44a261
Agree |
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.
Code review ACK d44a261
For background on this issue: the problem of wallet name truncation would have started happening for X:
style wallet dirs after #14561 and would have started happening for X:\
style wallet dirs after #20080, IIUC.
Long term fix should be switching lexically_relative
as described #21944 (comment)
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.
utACK d44a261
…ctory d44a261 Fix issues when `walletdir` is root directory (unknown) Pull request description: + Remove one character less from wallet path + After testing lot of random strings with special chars in `wallet_name`, I found that the issue was not related to special characters in the name. Reviewing PR bitcoin#21907 helped me resolve the issue. **Real issue**: If the path mentioned in `walletdir` is a root directory, first character of the wallet name or path is removed **Solution**: `if` statement to check `walletdir` is a root directory Fixes: bitcoin#21510 bitcoin#21501 Related PR: bitcoin#20080 Consider the wallet directories `w1` and `w2` saved in `D:\`. Run `bitcoind.exe -walletdir=D:\`, Results for `bitcoin-cli.exe listwalletdir`: Before this PR: ``` { "wallets": [ { "name": "1" }, { "name": "2" } ] } ``` After this PR: ``` "wallets": [ { "name": "w1" }, { "name": "w2" } ] } ``` ACKs for top commit: ryanofsky: Code review ACK d44a261 meshcollider: utACK d44a261 Tree-SHA512: b09b00f727407e3771c8694861dae1bfd29d97a0d51ddcb5d9c0111dc618b3fff2f75829cbb4361c54457ee564e94fcefd9e2928262a1c918a2b6bbad724eb55
+ Remove one character less from wallet path if root directory Github-Pull: bitcoin#21944 Rebased-From: d44a261
Remove one character less from wallet path
After testing lot of random strings with special chars in
wallet_name
, I found that the issue was not related to special characters in the name. Reviewing PR wallet: Do not iterate a directory if having an error while accessing it #21907 helped me resolve the issue.Real issue: If the path mentioned in
walletdir
is a root directory, first character of the wallet name or path is removedSolution:
if
statement to checkwalletdir
is a root directoryFixes: #21510 #21501
Related PR: #20080
Consider the wallet directories
w1
andw2
saved inD:\
. Runbitcoind.exe -walletdir=D:\
, Results forbitcoin-cli.exe listwalletdir
:Before this PR:
After this PR: