diff options
author | Gavin Andresen <gavinandresen@gmail.com> | 2011-11-17 14:21:32 -0500 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2011-11-17 14:29:18 -0500 |
commit | c4a3bf9e552f25a5ad0efb8cf62d344a7dad53ed (patch) | |
tree | aafa2dc7d55650358dd822825dfcc7a2ac415023 | |
parent | 90de05e88ecc879b75315eebacb488b44353f5d9 (diff) | |
download | bitcoin-c4a3bf9e552f25a5ad0efb8cf62d344a7dad53ed.tar.xz |
Only remove database log files on shutdown after wallet encryption/rewrite
-rw-r--r-- | src/db.cpp | 13 | ||||
-rw-r--r-- | src/db.h | 3 | ||||
-rw-r--r-- | src/init.cpp | 4 | ||||
-rw-r--r-- | src/wallet.cpp | 5 |
4 files changed, 16 insertions, 9 deletions
diff --git a/src/db.cpp b/src/db.cpp index b48be7ab75..77000ab00e 100644 --- a/src/db.cpp +++ b/src/db.cpp @@ -28,7 +28,12 @@ DbEnv dbenv(0); static map<string, int> mapFileUseCount; static map<string, Db*> mapDb; -static void EnvShutdown(bool fRemoveLogFiles) +static bool fRemoveLogFiles = false; +void RemoveLogFilesOnShutdown(bool fIn) +{ + fRemoveLogFiles = fIn; +} +static void EnvShutdown() { if (!fDbEnvInit) return; @@ -71,7 +76,7 @@ public: } ~CDBInit() { - EnvShutdown(false); + EnvShutdown(); } } instance_of_cdbinit; @@ -289,7 +294,7 @@ bool CDB::Rewrite(const string& strFile, const char* pszSkip) } -void DBFlush(bool fShutdown, bool fRemoveLogFiles) +void DBFlush(bool fShutdown) { // Flush log data to the actual data file // on all files that are not in use @@ -322,7 +327,7 @@ void DBFlush(bool fShutdown, bool fRemoveLogFiles) if (mapFileUseCount.empty()) { dbenv.log_archive(&listp, DB_ARCH_REMOVE); - EnvShutdown(fRemoveLogFiles); + EnvShutdown(); } } } @@ -29,7 +29,8 @@ extern unsigned int nWalletDBUpdated; extern DbEnv dbenv; -extern void DBFlush(bool fShutdown, bool fRemoveLogFiles); +extern void RemoveLogFilesOnShutdown(bool fRemoveLogFiles); +extern void DBFlush(bool fShutdown); void ThreadFlushWalletDB(void* parg); bool BackupWallet(const CWallet& wallet, const std::string& strDest); diff --git a/src/init.cpp b/src/init.cpp index 4a149b31bf..2d21a26143 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -45,9 +45,9 @@ void Shutdown(void* parg) { fShutdown = true; nTransactionsUpdated++; - DBFlush(false, false); + DBFlush(false); StopNode(); - DBFlush(true, true); + DBFlush(true); boost::filesystem::remove(GetPidFile()); UnregisterWallet(pwalletMain); delete pwalletMain; diff --git a/src/wallet.cpp b/src/wallet.cpp index 9b9586face..737f0e6238 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -194,8 +194,8 @@ bool CWallet::EncryptWallet(const string& strWalletPassphrase) // 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. - setKeyPool.clear(); - CDB::Rewrite(strWalletFile); + if (CDB::Rewrite(strWalletFile)) + RemoveLogFilesOnShutdown(true); } return true; @@ -1134,6 +1134,7 @@ int CWallet::LoadWallet(bool& fFirstRunRet) { if (CDB::Rewrite(strWalletFile, "\x04pool")) { + RemoveLogFilesOnShutdown(true); setKeyPool.clear(); // Note: can't top-up keypool here, because wallet is locked. // User will be prompted to unlock wallet the next operation |