Skip to content

Commit 9a64375

Browse files
authored
[BugFix] fix permission denied error when lock file is placed in /tmp (#317)
1 parent e2f121b commit 9a64375

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
@@ -4,6 +4,7 @@
44
import sys
55
from contextlib import suppress
66
from errno import ENOSYS
7+
from pathlib import Path
78
from typing import cast
89

910
from ._api import BaseFileLock
@@ -35,7 +36,9 @@ class UnixFileLock(BaseFileLock):
3536

3637
def _acquire(self) -> None:
3738
ensure_directory_exists(self.lock_file)
38-
open_flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC
39+
open_flags = os.O_RDWR | os.O_TRUNC
40+
if not Path(self.lock_file).exists():
41+
open_flags |= os.O_CREAT
3942
fd = os.open(self.lock_file, open_flags, self._context.mode)
4043
with suppress(PermissionError): # This locked is not owned by this UID
4144
os.fchmod(fd, self._context.mode)

0 commit comments

Comments
 (0)