Skip to content

Commit 1ec4b84

Browse files
committed
[WalletDb] Decouple custom backup path parsing from BackupWallet function.
1 parent 78c8679 commit 1ec4b84

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

src/wallet/walletdb.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -928,27 +928,33 @@ void NotifyBacked(const CWallet& wallet, bool fSuccess, std::string strMessage)
928928
wallet.NotifyWalletBacked(fSuccess, strMessage);
929929
}
930930

931-
bool BackupWallet(const CWallet& wallet, const fs::path& strDest, bool fEnableCustom)
931+
// Returns first the pathCustom, second the pathWithFile.
932+
std::pair<fs::path, fs::path> GetBackupPath(const CWallet& wallet)
932933
{
933934
fs::path pathCustom;
934-
fs::path pathWithFile;
935-
if(fEnableCustom) {
936-
pathWithFile = gArgs.GetArg("-backuppath", "");
937-
if(!pathWithFile.empty()) {
938-
if(!pathWithFile.has_extension()) {
939-
pathCustom = pathWithFile;
940-
pathWithFile /= wallet.GetUniqueWalletBackupName();
941-
} else {
942-
pathCustom = pathWithFile.parent_path();
943-
}
944-
try {
945-
fs::create_directories(pathCustom);
946-
} catch (const fs::filesystem_error& e) {
947-
NotifyBacked(wallet, false, strprintf("%s\n", e.what()));
948-
pathCustom = "";
949-
}
935+
fs::path pathWithFile = gArgs.GetArg("-backuppath", "");
936+
if(!pathWithFile.empty()) {
937+
if(!pathWithFile.has_extension()) {
938+
pathCustom = pathWithFile;
939+
pathWithFile /= wallet.GetUniqueWalletBackupName();
940+
} else {
941+
pathCustom = pathWithFile.parent_path();
942+
}
943+
try {
944+
fs::create_directories(pathCustom);
945+
} catch (const fs::filesystem_error& e) {
946+
NotifyBacked(wallet, false, strprintf("%s\n", e.what()));
947+
pathCustom = "";
950948
}
951949
}
950+
return {pathCustom, pathWithFile};
951+
}
952+
953+
bool BackupWallet(const CWallet& wallet, const fs::path& strDest)
954+
{
955+
const auto& pathsPair = GetBackupPath(wallet);
956+
fs::path pathCustom = pathsPair.first;
957+
fs::path pathWithFile = pathsPair.second;
952958

953959
while (true) {
954960
{

src/wallet/walletdb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class CWalletDB
227227
};
228228

229229
void NotifyBacked(const CWallet& wallet, bool fSuccess, std::string strMessage);
230-
bool BackupWallet(const CWallet& wallet, const fs::path& strDest, bool fEnableCustom = true);
230+
bool BackupWallet(const CWallet& wallet, const fs::path& strDest);
231231
bool AttemptBackupWallet(const CWallet& wallet, const fs::path& pathSrc, const fs::path& pathDest);
232232

233233
void ThreadFlushWalletDB();

0 commit comments

Comments
 (0)