Mercurial > hg > bitcoin
diff db.cpp @ 265:93404ec169c9 draft
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
author | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> |
---|---|
date | Mon, 06 Sep 2010 21:03:04 +0000 |
parents | bbd929786bd5 |
children | d220df352119 6c67c56991a1 |
line wrap: on
line diff
--- a/db.cpp +++ b/db.cpp @@ -81,7 +81,7 @@ 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 @@ 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 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); + } +}