mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
merge bitcoin#25898: remove WSL 1 workaround in fs
This commit is contained in:
parent
da5b433909
commit
05fb206f76
32
src/fs.cpp
32
src/fs.cpp
@ -62,36 +62,20 @@ FileLock::~FileLock()
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsWSL()
|
||||
{
|
||||
struct utsname uname_data;
|
||||
return uname(&uname_data) == 0 && std::string(uname_data.version).find("Microsoft") != std::string::npos;
|
||||
}
|
||||
|
||||
bool FileLock::TryLock()
|
||||
{
|
||||
if (fd == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Exclusive file locking is broken on WSL using fcntl (issue #18622)
|
||||
// This workaround can be removed once the bug on WSL is fixed
|
||||
static const bool is_wsl = IsWSL();
|
||||
if (is_wsl) {
|
||||
if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
|
||||
reason = GetErrorReason();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
struct flock lock;
|
||||
lock.l_type = F_WRLCK;
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 0;
|
||||
if (fcntl(fd, F_SETLK, &lock) == -1) {
|
||||
reason = GetErrorReason();
|
||||
return false;
|
||||
}
|
||||
struct flock lock;
|
||||
lock.l_type = F_WRLCK;
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 0;
|
||||
if (fcntl(fd, F_SETLK, &lock) == -1) {
|
||||
reason = GetErrorReason();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user