Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/db.cpp
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | |||||
CCriticalSection cs_db; | CCriticalSection cs_db; | ||||
//!< Map from directory name to open db environment. | //!< Map from directory name to open db environment. | ||||
std::map<std::string, CDBEnv> g_dbenvs; | std::map<std::string, CDBEnv> g_dbenvs; | ||||
} // namespace | } // namespace | ||||
CDBEnv *GetWalletEnv(const fs::path &wallet_path, | CDBEnv *GetWalletEnv(const fs::path &wallet_path, | ||||
std::string &database_filename) { | std::string &database_filename) { | ||||
fs::path env_directory = wallet_path.parent_path(); | 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(); | 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); | LOCK(cs_db); | ||||
// Note: An ununsed temporary CDBEnv object may be created inside the | // Note: An ununsed temporary CDBEnv object may be created inside the | ||||
// emplace function if the key already exists. This is a little inefficient, | // emplace function if the key already exists. This is a little inefficient, | ||||
// but not a big concern since the map will be changed in the future to hold | // but not a big concern since the map will be changed in the future to hold | ||||
// pointers instead of objects, anyway. | // pointers instead of objects, anyway. | ||||
return &g_dbenvs | return &g_dbenvs | ||||
.emplace(std::piecewise_construct, | .emplace(std::piecewise_construct, | ||||
std::forward_as_tuple(env_directory.string()), | std::forward_as_tuple(env_directory.string()), | ||||
▲ Show 20 Lines • Show All 768 Lines • Show Last 20 Lines |