mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
add unicode compatible file_lock for Windows
boost::interprocess::file_lock cannot open the files that contain characters which cannot be parsed by the user's code page on Windows. This commit add a new class to handle those specific file for Windows.
This commit is contained in:
22
src/util.cpp
22
src/util.cpp
@@ -71,7 +71,6 @@
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
#include <boost/interprocess/sync/file_lock.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/rand.h>
|
||||
@@ -139,7 +138,7 @@ instance_of_cinit;
|
||||
* cleans them up and thus automatically unlocks them, or ReleaseDirectoryLocks
|
||||
* is called.
|
||||
*/
|
||||
static std::map<std::string, std::unique_ptr<boost::interprocess::file_lock>> dir_locks;
|
||||
static std::map<std::string, std::unique_ptr<fsbridge::FileLock>> dir_locks;
|
||||
/** Mutex to protect dir_locks. */
|
||||
static std::mutex cs_dir_locks;
|
||||
|
||||
@@ -156,18 +155,13 @@ bool LockDirectory(const fs::path& directory, const std::string lockfile_name, b
|
||||
// Create empty lock file if it doesn't exist.
|
||||
FILE* file = fsbridge::fopen(pathLockFile, "a");
|
||||
if (file) fclose(file);
|
||||
|
||||
try {
|
||||
auto lock = MakeUnique<boost::interprocess::file_lock>(pathLockFile.string().c_str());
|
||||
if (!lock->try_lock()) {
|
||||
return false;
|
||||
}
|
||||
if (!probe_only) {
|
||||
// Lock successful and we're not just probing, put it into the map
|
||||
dir_locks.emplace(pathLockFile.string(), std::move(lock));
|
||||
}
|
||||
} catch (const boost::interprocess::interprocess_exception& e) {
|
||||
return error("Error while attempting to lock directory %s: %s", directory.string(), e.what());
|
||||
auto lock = MakeUnique<fsbridge::FileLock>(pathLockFile);
|
||||
if (!lock->TryLock()) {
|
||||
return error("Error while attempting to lock directory %s: %s", directory.string(), lock->GetReason());
|
||||
}
|
||||
if (!probe_only) {
|
||||
// Lock successful and we're not just probing, put it into the map
|
||||
dir_locks.emplace(pathLockFile.string(), std::move(lock));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user