File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4546,9 +4546,20 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
45464546 return util::Error{_ (" Error: This wallet is already a descriptor wallet" )};
45474547 }
45484548
4549- // Make a backup of the DB
4549+ // Make a backup of the DB in the wallet's directory with a unique filename
4550+ // using the wallet name and current timestamp. The backup filename is based
4551+ // on the name of the parent directory containing the wallet data in most
4552+ // cases, but in the case where the wallet name is a path to a data file,
4553+ // the name of the data file is used, and in the case where the wallet name
4554+ // is blank, "default_wallet" is used.
45504555 fs::path this_wallet_dir = fs::absolute (fs::PathFromString (local_wallet->GetDatabase ().Filename ())).parent_path ();
4551- fs::path backup_filename = fs::PathFromString (strprintf (" %s_%d.legacy.bak" , MigrationPrefixName (*local_wallet), GetTime ()));
4556+ const std::string backup_prefix = wallet_name.empty () ? MigrationPrefixName (*local_wallet) : [&] {
4557+ // fs::weakly_canonical resolves relative specifiers and remove trailing slashes.
4558+ const auto legacy_wallet_path = fs::weakly_canonical (GetWalletDir () / fs::PathFromString (wallet_name));
4559+ return fs::PathToString (legacy_wallet_path.filename ());
4560+ }();
4561+
4562+ fs::path backup_filename = fs::PathFromString (strprintf (" %s_%d.legacy.bak" , backup_prefix, GetTime ()));
45524563 fs::path backup_path = this_wallet_dir / backup_filename;
45534564 if (!local_wallet->BackupWallet (fs::PathToString (backup_path))) {
45544565 if (was_loaded) {
Original file line number Diff line number Diff line change @@ -636,7 +636,7 @@ def test_migration_failure(self, wallet_name):
636636 assert Path (old_path / "wallet.dat" ).exists ()
637637 assert Path (master_path / "wallet.dat" ).exists ()
638638
639- backup_prefix = "default_wallet" if is_default else wallet_name
639+ backup_prefix = "default_wallet" if is_default else os . path . basename ( os . path . abspath ( master_path ))
640640 backup_path = master_path / f"{ backup_prefix } _{ mocked_time } .legacy.bak"
641641 assert backup_path .exists ()
642642
You can’t perform that action at this time.
0 commit comments