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
This commit is contained in:
s_nakamoto
2010-09-06 21:03:04 +00:00
parent 0a61b0df12
commit d743f03552
4 changed files with 188 additions and 85 deletions

33
db.cpp
View File

@@ -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);
}
}