diff options
author | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-09-06 21:03:04 +0000 |
---|---|---|
committer | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> | 2010-09-06 21:03:04 +0000 |
commit | d743f0355269e2e03fe3f982e250d07999d72b98 (patch) | |
tree | f0b6916122bc1ddb7ff44df06ec417280f7fedcb /db.cpp | |
parent | 0a61b0df1224a5470bcddab302bc199ca5a9e356 (diff) |
Gavin Andresen: json-rpc return standard error objects with error code numbers,
json-rpc command line client return exit code,
added rpc backupwallet command
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@147 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'db.cpp')
-rw-r--r-- | db.cpp | 33 |
1 files changed, 31 insertions, 2 deletions
@@ -81,7 +81,7 @@ CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL) DB_RECOVER, S_IRUSR | S_IWUSR); if (ret > 0) - throw runtime_error(strprintf("CDB() : error %d opening database environment\n", ret)); + throw runtime_error(strprintf("CDB() : error %d opening database environment", ret)); fDbEnvInit = true; } @@ -106,7 +106,7 @@ CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL) CRITICAL_BLOCK(cs_db) --mapFileUseCount[strFile]; strFile = ""; - throw runtime_error(strprintf("CDB() : can't open database file %s, error %d\n", pszFile, ret)); + throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret)); } if (fCreate && !Exists(string("version"))) @@ -803,3 +803,32 @@ void ThreadFlushWalletDB(void* parg) } } } + +void BackupWallet(const string& strDest) +{ + while (!fShutdown) + { + CRITICAL_BLOCK(cs_db) + { + const string strFile = "wallet.dat"; + if (!mapFileUseCount.count(strFile) || mapFileUseCount[strFile] == 0) + { + // Flush log data to the dat file + CloseDb(strFile); + dbenv.txn_checkpoint(0, 0, 0); + dbenv.lsn_reset(strFile.c_str(), 0); + mapFileUseCount.erase(strFile); + + // Copy wallet.dat + filesystem::path pathDest(strDest); + if (filesystem::is_directory(pathDest)) + pathDest = pathDest / strFile; + filesystem::copy_file(filesystem::path(GetDataDir() + "/" + strFile), pathDest, filesystem::copy_option::overwrite_if_exists); + printf("copied wallet.dat to %s\n", pathDest.string().c_str()); + + return; + } + } + Sleep(100); + } +} |