Skip to content

Commit

Permalink
Merge pull request #2717 from div72/upstream_3995c88e
Browse files Browse the repository at this point in the history
util: remove WSL 1 workaround in fs
  • Loading branch information
jamescowens authored Dec 10, 2023
2 parents 82ee638 + ea91507 commit e96c092
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions src/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,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;
Expand Down

0 comments on commit e96c092

Please sign in to comment.