mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Create new wallet databases as directories rather than files
This change should make it easier for users to make complete backups of wallets because they can now just back up the specified `-wallet=<path>` path directly, instead of having to back up the specified path as well as the transaction log directory (for incompletely flushed wallets). Another advantage of this change is that if two wallets are located in the same directory, they will now use their own BerkeleyDB environments instead using a shared environment. Using a shared environment makes it difficult to manage and back up wallets separately because transaction log files will contain a mix of data from all wallets in the environment.
This commit is contained in:
@@ -59,8 +59,19 @@ std::map<std::string, CDBEnv> g_dbenvs; //!< Map from directory name to open db
|
||||
|
||||
CDBEnv* GetWalletEnv(const fs::path& wallet_path, std::string& database_filename)
|
||||
{
|
||||
fs::path env_directory = wallet_path.parent_path();
|
||||
database_filename = wallet_path.filename().string();
|
||||
fs::path env_directory;
|
||||
if (fs::is_regular_file(wallet_path)) {
|
||||
// Special case for backwards compatibility: if wallet path points to an
|
||||
// existing file, treat it as the path to a BDB data file in a parent
|
||||
// directory that also contains BDB log files.
|
||||
env_directory = wallet_path.parent_path();
|
||||
database_filename = wallet_path.filename().string();
|
||||
} else {
|
||||
// Normal case: Interpret wallet path as a directory path containing
|
||||
// data and log files.
|
||||
env_directory = wallet_path;
|
||||
database_filename = "wallet.dat";
|
||||
}
|
||||
LOCK(cs_db);
|
||||
// Note: An ununsed temporary CDBEnv object may be created inside the
|
||||
// emplace function if the key already exists. This is a little inefficient,
|
||||
|
||||
Reference in New Issue
Block a user