File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -4229,8 +4229,19 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
4229
4229
return util::Error{_ (" Error: This wallet is already a descriptor wallet" )};
4230
4230
}
4231
4231
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 ()));
4234
4245
fs::path backup_path = fsbridge::AbsPathJoin (GetWalletDir (), backup_filename);
4235
4246
if (!local_wallet->BackupWallet (fs::PathToString (backup_path))) {
4236
4247
return util::Error{_ (" Error: Unable to make a backup of your wallet" )};
You can’t perform that action at this time.
0 commit comments