From 2f3bd47d44634cfc0a4261e64af178407ce2869c Mon Sep 17 00:00:00 2001 From: MeshCollider Date: Tue, 26 Dec 2017 19:41:55 +1300 Subject: Abstract directory locking into util.cpp --- src/wallet/db.cpp | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'src/wallet/db.cpp') diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index e3366e1060..23c6279128 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -18,7 +18,6 @@ #include #endif -#include #include namespace { @@ -53,24 +52,6 @@ void CheckUniqueFileid(const CDBEnv& env, const std::string& filename, Db& db) } } } - -bool LockEnvDirectory(const fs::path& env_path) -{ - // Make sure only a single Bitcoin process is using the wallet directory. - fs::path lock_file_path = env_path / ".walletlock"; - FILE* file = fsbridge::fopen(lock_file_path, "a"); // empty lock file; created if it doesn't exist. - if (file) fclose(file); - - try { - static boost::interprocess::file_lock lock(lock_file_path.string().c_str()); - if (!lock.try_lock()) { - return false; - } - } catch (const boost::interprocess::interprocess_exception& e) { - return error("Error obtaining lock on wallet directory %s: %s.", env_path.string(), e.what()); - } - return true; -} } // namespace // @@ -122,7 +103,7 @@ bool CDBEnv::Open(const fs::path& pathIn, bool retry) boost::this_thread::interruption_point(); strPath = pathIn.string(); - if (!LockEnvDirectory(pathIn)) { + if (!LockDirectory(pathIn, ".walletlock")) { LogPrintf("Cannot obtain a lock on wallet directory %s. Another instance of bitcoin may be using it.\n", strPath); return false; } -- cgit v1.2.3