Move wallet backup dir check to wallet.cpp

Also remove caching in GetBackupsDir(). Not much is gained by this as we
don't call GetBackupsDir() that often.

Also add a is_directory check in AutoBackupWallet to handle cases where the
user deletes or moves the dir while Dash is running.
This commit is contained in:
Alexander Block 2018-01-18 17:55:51 +01:00
parent ec8a9e0a6d
commit 2e02b167ea
3 changed files with 20 additions and 25 deletions

View File

@ -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()

View File

@ -19,7 +19,6 @@
#include "tinyformat.h"
#include "utiltime.h"
#include "amount.h"
#include "warnings.h"
#include <atomic>
#include <exception>
@ -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();

View File

@ -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 ...