aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
authorPatrick Strateman <patrick.strateman@gmail.com>2016-05-16 17:31:16 -0700
committerPatrick Strateman <patrick.strateman@gmail.com>2016-05-16 17:48:25 -0700
commit380498aba4f6aebe53a8241f163e3c7fe424b7e0 (patch)
treec191b564f4bcb915de931d85f661e64045cc65e6 /src/wallet/wallet.cpp
parentecb9741ec3067f67f595126869d0200c62064bbd (diff)
downloadbitcoin-380498aba4f6aebe53a8241f163e3c7fe424b7e0.tar.xz
Move BackupWallet to CWallet::BackupWallet
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 4809e3baa6..5d1a431190 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -3283,6 +3283,46 @@ bool CWallet::ParameterInteraction()
return true;
}
+bool CWallet::BackupWallet(const std::string& strDest)
+{
+ if (!fFileBacked)
+ return false;
+ while (true)
+ {
+ {
+ LOCK(bitdb.cs_db);
+ if (!bitdb.mapFileUseCount.count(strWalletFile) || bitdb.mapFileUseCount[strWalletFile] == 0)
+ {
+ // Flush log data to the dat file
+ bitdb.CloseDb(strWalletFile);
+ bitdb.CheckpointLSN(strWalletFile);
+ bitdb.mapFileUseCount.erase(strWalletFile);
+
+ // Copy wallet file
+ boost::filesystem::path pathSrc = GetDataDir() / strWalletFile;
+ boost::filesystem::path pathDest(strDest);
+ if (boost::filesystem::is_directory(pathDest))
+ pathDest /= strWalletFile;
+
+ try {
+#if BOOST_VERSION >= 104000
+ boost::filesystem::copy_file(pathSrc, pathDest, boost::filesystem::copy_option::overwrite_if_exists);
+#else
+ boost::filesystem::copy_file(pathSrc, pathDest);
+#endif
+ LogPrintf("copied %s to %s\n", strWalletFile, pathDest.string());
+ return true;
+ } catch (const boost::filesystem::filesystem_error& e) {
+ LogPrintf("error copying %s to %s - %s\n", strWalletFile, pathDest.string(), e.what());
+ return false;
+ }
+ }
+ }
+ MilliSleep(100);
+ }
+ return false;
+}
+
CKeyPool::CKeyPool()
{
nTime = GetTime();