Skip to content

Commit 70f1c99

Browse files
wallet: Fix migration of wallets with pathnames.
Co-authored-by: Russell Yanofsky <[email protected]>
1 parent f6ee59b commit 70f1c99

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/wallet/wallet.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4229,8 +4229,19 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
42294229
return util::Error{_("Error: This wallet is already a descriptor wallet")};
42304230
}
42314231

4232-
// Make a backup of the DB
4233-
fs::path backup_filename = fs::PathFromString(strprintf("%s_%d.legacy.bak", (wallet_name.empty() ? "default_wallet" : wallet_name), GetTime()));
4232+
// Make a backup of the DB in the wallet's directory with a unique filename
4233+
// using the wallet name and current timestamp. The backup filename is based
4234+
// on the name of the parent directory containing the wallet data in most
4235+
// cases, but in the case where the wallet name is a path to a data file,
4236+
// the name of the data file is used, and in the case where the wallet name
4237+
// is blank, "default_wallet" is used.
4238+
const std::string backup_prefix = wallet_name.empty() ? "default_wallet" : [&] {
4239+
// fs::weakly_canonical resolves relative specifiers and remove trailing slashes.
4240+
const auto legacy_wallet_path = fs::weakly_canonical(GetWalletDir() / fs::PathFromString(wallet_name));
4241+
return fs::PathToString(legacy_wallet_path.filename());
4242+
}();
4243+
4244+
fs::path backup_filename = fs::PathFromString(strprintf("%s_%d.legacy.bak", backup_prefix, GetTime()));
42344245
fs::path backup_path = fsbridge::AbsPathJoin(GetWalletDir(), backup_filename);
42354246
if (!local_wallet->BackupWallet(fs::PathToString(backup_path))) {
42364247
return util::Error{_("Error: Unable to make a backup of your wallet")};

0 commit comments

Comments
 (0)