mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Add -walletdir parameter to specify custom wallet dir
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <protocol.h>
|
||||
#include <util.h>
|
||||
#include <utilstrencodings.h>
|
||||
#include <wallet/walletutil.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -257,7 +258,7 @@ bool CDB::Recover(const std::string& filename, void *callbackDataIn, bool (*reco
|
||||
return fSuccess;
|
||||
}
|
||||
|
||||
bool CDB::VerifyEnvironment(const std::string& walletFile, const fs::path& dataDir, std::string& errorStr)
|
||||
bool CDB::VerifyEnvironment(const std::string& walletFile, const fs::path& walletDir, std::string& errorStr)
|
||||
{
|
||||
LogPrintf("Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0));
|
||||
LogPrintf("Using wallet %s\n", walletFile);
|
||||
@@ -265,15 +266,15 @@ bool CDB::VerifyEnvironment(const std::string& walletFile, const fs::path& dataD
|
||||
// Wallet file must be a plain filename without a directory
|
||||
if (walletFile != fs::basename(walletFile) + fs::extension(walletFile))
|
||||
{
|
||||
errorStr = strprintf(_("Wallet %s resides outside data directory %s"), walletFile, dataDir.string());
|
||||
errorStr = strprintf(_("Wallet %s resides outside wallet directory %s"), walletFile, walletDir.string());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bitdb.Open(dataDir))
|
||||
if (!bitdb.Open(walletDir))
|
||||
{
|
||||
// try moving the database env out of the way
|
||||
fs::path pathDatabase = dataDir / "database";
|
||||
fs::path pathDatabaseBak = dataDir / strprintf("database.%d.bak", GetTime());
|
||||
fs::path pathDatabase = walletDir / "database";
|
||||
fs::path pathDatabaseBak = walletDir / strprintf("database.%d.bak", GetTime());
|
||||
try {
|
||||
fs::rename(pathDatabase, pathDatabaseBak);
|
||||
LogPrintf("Moved old %s to %s. Retrying.\n", pathDatabase.string(), pathDatabaseBak.string());
|
||||
@@ -282,18 +283,18 @@ bool CDB::VerifyEnvironment(const std::string& walletFile, const fs::path& dataD
|
||||
}
|
||||
|
||||
// try again
|
||||
if (!bitdb.Open(dataDir)) {
|
||||
if (!bitdb.Open(walletDir)) {
|
||||
// if it still fails, it probably means we can't even create the database env
|
||||
errorStr = strprintf(_("Error initializing wallet database environment %s!"), GetDataDir());
|
||||
errorStr = strprintf(_("Error initializing wallet database environment %s!"), walletDir);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDB::VerifyDatabaseFile(const std::string& walletFile, const fs::path& dataDir, std::string& warningStr, std::string& errorStr, CDBEnv::recoverFunc_type recoverFunc)
|
||||
bool CDB::VerifyDatabaseFile(const std::string& walletFile, const fs::path& walletDir, std::string& warningStr, std::string& errorStr, CDBEnv::recoverFunc_type recoverFunc)
|
||||
{
|
||||
if (fs::exists(dataDir / walletFile))
|
||||
if (fs::exists(walletDir / walletFile))
|
||||
{
|
||||
std::string backup_filename;
|
||||
CDBEnv::VerifyResult r = bitdb.Verify(walletFile, recoverFunc, backup_filename);
|
||||
@@ -303,7 +304,7 @@ bool CDB::VerifyDatabaseFile(const std::string& walletFile, const fs::path& data
|
||||
" Original %s saved as %s in %s; if"
|
||||
" your balance or transactions are incorrect you should"
|
||||
" restore from a backup."),
|
||||
walletFile, backup_filename, dataDir);
|
||||
walletFile, backup_filename, walletDir);
|
||||
}
|
||||
if (r == CDBEnv::RECOVER_FAIL)
|
||||
{
|
||||
@@ -407,7 +408,7 @@ CDB::CDB(CWalletDBWrapper& dbw, const char* pszMode, bool fFlushOnCloseIn) : pdb
|
||||
|
||||
{
|
||||
LOCK(env->cs_db);
|
||||
if (!env->Open(GetDataDir()))
|
||||
if (!env->Open(GetWalletDir()))
|
||||
throw std::runtime_error("CDB: Failed to open database environment.");
|
||||
|
||||
pdb = env->mapDb[strFilename];
|
||||
@@ -695,7 +696,7 @@ bool CWalletDBWrapper::Backup(const std::string& strDest)
|
||||
env->mapFileUseCount.erase(strFile);
|
||||
|
||||
// Copy wallet file
|
||||
fs::path pathSrc = GetDataDir() / strFile;
|
||||
fs::path pathSrc = GetWalletDir() / strFile;
|
||||
fs::path pathDest(strDest);
|
||||
if (fs::is_directory(pathDest))
|
||||
pathDest /= strFile;
|
||||
|
||||
Reference in New Issue
Block a user