diff --git a/src/util.cpp b/src/util.cpp index be0cfc9a5c..52f5a8b5de 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -608,33 +608,14 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) return path; } -static boost::filesystem::path backupsDirCached; -static CCriticalSection csBackupsDirCached; - -const boost::filesystem::path &GetBackupsDir() +boost::filesystem::path GetBackupsDir() { namespace fs = boost::filesystem; - LOCK(csBackupsDirCached); + if (!IsArgSet("-walletbackupsdir")) + return GetDataDir() / "backups"; - fs::path &backupsDir = backupsDirCached; - - if (!backupsDir.empty()) - return backupsDir; - - if (mapArgs.count("-walletbackupsdir")) { - backupsDir = fs::absolute(mapArgs["-walletbackupsdir"]); - // Path must exist - if (fs::is_directory(backupsDir)) return backupsDir; - // Fallback to default path if it doesn't - LogPrintf("%s: Warning: incorrect parameter -walletbackupsdir, path must exist! Using default path.\n", __func__); - // TODO this causes link errors for dash-cli. I tried to add LIBBITCOIN_COMMON to dash-cli, but with no luck - //SetMiscWarning(_("Warning: incorrect parameter -walletbackupsdir, path must exist! Using default path.")); - } - // Default path - backupsDir = GetDataDir() / "backups"; - - return backupsDir; + return fs::absolute(GetArg("-walletbackupsdir", "")); } void ClearDatadirCache() diff --git a/src/util.h b/src/util.h index 821f7ffd7e..739cc8a56c 100644 --- a/src/util.h +++ b/src/util.h @@ -19,7 +19,6 @@ #include "tinyformat.h" #include "utiltime.h" #include "amount.h" -#include "warnings.h" #include #include @@ -122,7 +121,7 @@ bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest); bool TryCreateDirectory(const boost::filesystem::path& p); boost::filesystem::path GetDefaultDataDir(); const boost::filesystem::path &GetDataDir(bool fNetSpecific = true); -const boost::filesystem::path &GetBackupsDir(); +boost::filesystem::path GetBackupsDir(); void ClearDatadirCache(); boost::filesystem::path GetConfigFile(const std::string& confPath); boost::filesystem::path GetMasternodeConfigFile(); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1f622ced82..d34d50f7c2 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -5027,6 +5027,15 @@ bool CWallet::ParameterInteraction() if (fSendFreeTransactions && GetArg("-limitfreerelay", DEFAULT_LIMITFREERELAY) <= 0) return InitError("Creation of free transactions with their relay disabled is not supported."); + if (IsArgSet("-walletbackupsdir")) { + if (!boost::filesystem::is_directory(GetArg("-walletbackupsdir", ""))) { + LogPrintf("%s: Warning: incorrect parameter -walletbackupsdir, path must exist! Using default path.\n", __func__); + InitWarning("Warning: incorrect parameter -walletbackupsdir, path must exist! Using default path.\n"); + + ForceRemoveArg("-walletbackupsdir"); + } + } + return true; } @@ -5116,6 +5125,12 @@ bool AutoBackupWallet (CWallet* wallet, std::string strWalletFile, std::string& nWalletBackups = -1; return false; } + } else if (!fs::is_directory(backupsDir)) { + // smth is wrong, we shouldn't continue until it's resolved + strBackupError = strprintf(_("%s is not a valid backup folder!"), backupsDir.string()); + LogPrintf("%s\n", strBackupError); + nWalletBackups = -1; + return false; } // Create backup of the ...