MCPcopy Create free account
hub / github.com/ElementsProject/elements / TryLock

Method TryLock

src/fs.cpp:71–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71bool FileLock::TryLock()
72{
73 if (fd == -1) {
74 return false;
75 }
76
77 // Exclusive file locking is broken on WSL using fcntl (issue #18622)
78 // This workaround can be removed once the bug on WSL is fixed
79 static const bool is_wsl = IsWSL();
80 if (is_wsl) {
81 if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
82 reason = GetErrorReason();
83 return false;
84 }
85 } else {
86 struct flock lock;
87 lock.l_type = F_WRLCK;
88 lock.l_whence = SEEK_SET;
89 lock.l_start = 0;
90 lock.l_len = 0;
91 if (fcntl(fd, F_SETLK, &lock) == -1) {
92 reason = GetErrorReason();
93 return false;
94 }
95 }
96
97 return true;
98}
99#else
100
101static std::string GetErrorReason() {

Callers 1

LockDirectoryFunction · 0.80

Calls 3

IsWSLFunction · 0.85
flockClass · 0.85
GetErrorReasonFunction · 0.85

Tested by

no test coverage detected