Skip to content

Commit ecba230

Browse files
committed
wallet: implement BerkeleyRODatabase::Backup
1 parent 0c8e728 commit ecba230

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/wallet/migrate.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Distributed under the MIT software license, see the accompanying
22
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
33

4+
#include <logging.h>
45
#include <wallet/migrate.h>
56

67
namespace wallet {
@@ -16,7 +17,25 @@ std::unique_ptr<DatabaseBatch> BerkeleyRODatabase::MakeBatch(bool flush_on_close
1617

1718
bool BerkeleyRODatabase::Backup(const std::string& dest) const
1819
{
19-
return false;
20+
fs::path src(m_filepath);
21+
fs::path dst(fs::PathFromString(dest));
22+
23+
if (fs::is_directory(dst)) {
24+
dst = BDBDataFile(dst);
25+
}
26+
try {
27+
if (fs::exists(dst) && fs::equivalent(src, dst)) {
28+
LogPrintf("cannot backup to wallet source file %s\n", fs::PathToString(dst));
29+
return false;
30+
}
31+
32+
fs::copy_file(src, dst, fs::copy_options::overwrite_existing);
33+
LogPrintf("copied %s to %s\n", fs::PathToString(m_filepath), fs::PathToString(dst));
34+
return true;
35+
} catch (const fs::filesystem_error& e) {
36+
LogPrintf("error copying %s to %s - %s\n", fs::PathToString(m_filepath), fs::PathToString(dst), fsbridge::get_filesystem_error_message(e));
37+
return false;
38+
}
2039
}
2140

2241
bool BerkeleyROBatch::ReadKey(DataStream&& key, DataStream& value)

0 commit comments

Comments
 (0)