fs: drop old WSL1 hack.

This commit is contained in:
sinetek committed 2022-09-09 22:07:17 +02:00
1 parent ef5bb742f0
commit 5669afb80e
1 file changed
+8 -24
+8 -24
View File
@@ -60,36 +60,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() bool FileLock::TryLock()
{ {
if (fd == -1) { if (fd == -1) {
return false; return false;
} }
// Exclusive file locking is broken on WSL using fcntl (issue #18622) struct flock lock;
// This workaround can be removed once the bug on WSL is fixed lock.l_type = F_WRLCK;
static const bool is_wsl = IsWSL(); lock.l_whence = SEEK_SET;
if (is_wsl) { lock.l_start = 0;
if (flock(fd, LOCK_EX | LOCK_NB) == -1) { lock.l_len = 0;
reason = GetErrorReason(); if (fcntl(fd, F_SETLK, &lock) == -1) {
return false; 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;
}
} }
return true; return true;