Skip to content

Commit 5088854

Browse files
authored
Support Unix systems without O_NOFOLLOW (#463)
Acquiring a lock uses the `O_NOFOLLOW` flag when calling `open`. However, this flag is not available on all platforms, such as GraalPy, causing an `AttributeError` to be raised when attempting to acquire a lock. According to the Python docs: > The above constants are extensions and not present if they are not > defined by the C library. This handles such platforms by checking for the presence of the `O_NOFOLLOW` flag first.
1 parent 377f622 commit 5088854

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/filelock/_unix.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ class UnixFileLock(BaseFileLock):
3838

3939
def _acquire(self) -> None:
4040
ensure_directory_exists(self.lock_file)
41-
open_flags = os.O_RDWR | os.O_TRUNC | os.O_NOFOLLOW
41+
open_flags = os.O_RDWR | os.O_TRUNC
42+
o_nofollow = getattr(os, "O_NOFOLLOW", None)
43+
if o_nofollow is not None:
44+
open_flags |= o_nofollow
4245
if not Path(self.lock_file).exists():
4346
open_flags |= os.O_CREAT
4447
fd = os.open(self.lock_file, open_flags, self._context.mode)

0 commit comments

Comments
 (0)