wallet: Fix migration of wallets with pathnames.
Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
This commit is contained in:
1 parent
f6ee59b6e2
commit
70f1c99c90
1 file changed
+13
-2
+13
-2
@@ -4229,8 +4229,19 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
|
|||||||
return util::Error{_("Error: This wallet is already a descriptor wallet")};
|
return util::Error{_("Error: This wallet is already a descriptor wallet")};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a backup of the DB
|
// Make a backup of the DB in the wallet's directory with a unique filename
|
||||||
fs::path backup_filename = fs::PathFromString(strprintf("%s_%d.legacy.bak", (wallet_name.empty() ? "default_wallet" : wallet_name), GetTime()));
|
// using the wallet name and current timestamp. The backup filename is based
|
||||||
|
// on the name of the parent directory containing the wallet data in most
|
||||||
|
// cases, but in the case where the wallet name is a path to a data file,
|
||||||
|
// the name of the data file is used, and in the case where the wallet name
|
||||||
|
// is blank, "default_wallet" is used.
|
||||||
|
const std::string backup_prefix = wallet_name.empty() ? "default_wallet" : [&] {
|
||||||
|
// fs::weakly_canonical resolves relative specifiers and remove trailing slashes.
|
||||||
|
const auto legacy_wallet_path = fs::weakly_canonical(GetWalletDir() / fs::PathFromString(wallet_name));
|
||||||
|
return fs::PathToString(legacy_wallet_path.filename());
|
||||||
|
}();
|
||||||
|
|
||||||
|
fs::path backup_filename = fs::PathFromString(strprintf("%s_%d.legacy.bak", backup_prefix, GetTime()));
|
||||||
fs::path backup_path = fsbridge::AbsPathJoin(GetWalletDir(), backup_filename);
|
fs::path backup_path = fsbridge::AbsPathJoin(GetWalletDir(), backup_filename);
|
||||||
if (!local_wallet->BackupWallet(fs::PathToString(backup_path))) {
|
if (!local_wallet->BackupWallet(fs::PathToString(backup_path))) {
|
||||||
return util::Error{_("Error: Unable to make a backup of your wallet")};
|
return util::Error{_("Error: Unable to make a backup of your wallet")};
|
||||||
|
|||||||
Reference in new issue
Block a user