aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/migrate.cpp
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2024-01-02 16:35:30 -0500
committerAva Chow <github@achow101.com>2024-05-13 23:01:38 -0400
commitecba23097955dad7208baa687fc405c846aee794 (patch)
treeef4823ddbf9ae39fff8091206646ba7a0c4f72b2 /src/wallet/migrate.cpp
parent0c8e72847603540bb29b8b8aeb80fa3f2e3a2c9a (diff)
downloadbitcoin-ecba23097955dad7208baa687fc405c846aee794.tar.xz
wallet: implement BerkeleyRODatabase::Backup
Diffstat (limited to 'src/wallet/migrate.cpp')
-rw-r--r--src/wallet/migrate.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/wallet/migrate.cpp b/src/wallet/migrate.cpp
index f922d99a17..4c37dfee6f 100644
--- a/src/wallet/migrate.cpp
+++ b/src/wallet/migrate.cpp
@@ -1,6 +1,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <logging.h>
#include <wallet/migrate.h>
namespace wallet {
@@ -16,7 +17,25 @@ std::unique_ptr<DatabaseBatch> BerkeleyRODatabase::MakeBatch(bool flush_on_close
bool BerkeleyRODatabase::Backup(const std::string& dest) const
{
- return false;
+ fs::path src(m_filepath);
+ fs::path dst(fs::PathFromString(dest));
+
+ if (fs::is_directory(dst)) {
+ dst = BDBDataFile(dst);
+ }
+ try {
+ if (fs::exists(dst) && fs::equivalent(src, dst)) {
+ LogPrintf("cannot backup to wallet source file %s\n", fs::PathToString(dst));
+ return false;
+ }
+
+ fs::copy_file(src, dst, fs::copy_options::overwrite_existing);
+ LogPrintf("copied %s to %s\n", fs::PathToString(m_filepath), fs::PathToString(dst));
+ return true;
+ } catch (const fs::filesystem_error& e) {
+ LogPrintf("error copying %s to %s - %s\n", fs::PathToString(m_filepath), fs::PathToString(dst), fsbridge::get_filesystem_error_message(e));
+ return false;
+ }
}
bool BerkeleyROBatch::ReadKey(DataStream&& key, DataStream& value)