Never remove database files on shutdown, it caused unreadable wallets on some testers' machines.
This commit is contained in:
parent
1c15f88653
commit
b2d3b2d65d
3 changed files with 1 additions and 28 deletions
23
src/db.cpp
23
src/db.cpp
|
@ -28,11 +28,6 @@ DbEnv dbenv(0);
|
||||||
static map<string, int> mapFileUseCount;
|
static map<string, int> mapFileUseCount;
|
||||||
static map<string, Db*> mapDb;
|
static map<string, Db*> mapDb;
|
||||||
|
|
||||||
static bool fRemoveLogFiles = false;
|
|
||||||
void RemoveLogFilesOnShutdown(bool fIn)
|
|
||||||
{
|
|
||||||
fRemoveLogFiles = fIn;
|
|
||||||
}
|
|
||||||
static void EnvShutdown()
|
static void EnvShutdown()
|
||||||
{
|
{
|
||||||
if (!fDbEnvInit)
|
if (!fDbEnvInit)
|
||||||
|
@ -48,24 +43,6 @@ static void EnvShutdown()
|
||||||
printf("EnvShutdown exception: %s (%d)\n", e.what(), e.get_errno());
|
printf("EnvShutdown exception: %s (%d)\n", e.what(), e.get_errno());
|
||||||
}
|
}
|
||||||
DbEnv(0).remove(GetDataDir().c_str(), 0);
|
DbEnv(0).remove(GetDataDir().c_str(), 0);
|
||||||
|
|
||||||
if (fRemoveLogFiles)
|
|
||||||
{
|
|
||||||
filesystem::path datadir(GetDataDir());
|
|
||||||
filesystem::directory_iterator it(datadir / "database");
|
|
||||||
while (it != filesystem::directory_iterator())
|
|
||||||
{
|
|
||||||
const filesystem::path& p = it->path();
|
|
||||||
#if BOOST_FILESYSTEM_VERSION >= 3
|
|
||||||
std::string f = p.filename().generic_string();
|
|
||||||
#else
|
|
||||||
std::string f = p.filename();
|
|
||||||
#endif
|
|
||||||
if (f.find("log.") == 0)
|
|
||||||
filesystem::remove(p);
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CDBInit
|
class CDBInit
|
||||||
|
|
2
src/db.h
2
src/db.h
|
@ -28,8 +28,6 @@ class CBlockLocator;
|
||||||
extern unsigned int nWalletDBUpdated;
|
extern unsigned int nWalletDBUpdated;
|
||||||
extern DbEnv dbenv;
|
extern DbEnv dbenv;
|
||||||
|
|
||||||
|
|
||||||
extern void RemoveLogFilesOnShutdown(bool fRemoveLogFiles);
|
|
||||||
extern void DBFlush(bool fShutdown);
|
extern void DBFlush(bool fShutdown);
|
||||||
void ThreadFlushWalletDB(void* parg);
|
void ThreadFlushWalletDB(void* parg);
|
||||||
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
|
bool BackupWallet(const CWallet& wallet, const std::string& strDest);
|
||||||
|
|
|
@ -193,8 +193,7 @@ bool CWallet::EncryptWallet(const string& strWalletPassphrase)
|
||||||
|
|
||||||
// Need to completely rewrite the wallet file; if we don't, bdb might keep
|
// Need to completely rewrite the wallet file; if we don't, bdb might keep
|
||||||
// bits of the unencrypted private key in slack space in the database file.
|
// bits of the unencrypted private key in slack space in the database file.
|
||||||
if (CDB::Rewrite(strWalletFile))
|
CDB::Rewrite(strWalletFile);
|
||||||
RemoveLogFilesOnShutdown(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1154,7 +1153,6 @@ int CWallet::LoadWallet(bool& fFirstRunRet)
|
||||||
{
|
{
|
||||||
if (CDB::Rewrite(strWalletFile, "\x04pool"))
|
if (CDB::Rewrite(strWalletFile, "\x04pool"))
|
||||||
{
|
{
|
||||||
RemoveLogFilesOnShutdown(true);
|
|
||||||
setKeyPool.clear();
|
setKeyPool.clear();
|
||||||
// Note: can't top-up keypool here, because wallet is locked.
|
// Note: can't top-up keypool here, because wallet is locked.
|
||||||
// User will be prompted to unlock wallet the next operation
|
// User will be prompted to unlock wallet the next operation
|
||||||
|
|
Loading…
Reference in a new issue