Skip to content

Commit

Permalink
[BugFix] fix permission denied error when lock file is placed in `/tm…
Browse files Browse the repository at this point in the history
…p` (#317)
  • Loading branch information
kota-iizuka committed Mar 25, 2024
1 parent e2f121b commit 9a64375
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/filelock/_unix.py
Expand Up @@ -4,6 +4,7 @@
import sys
from contextlib import suppress
from errno import ENOSYS
from pathlib import Path
from typing import cast

from ._api import BaseFileLock
Expand Down Expand Up @@ -35,7 +36,9 @@ class UnixFileLock(BaseFileLock):

def _acquire(self) -> None:
ensure_directory_exists(self.lock_file)
open_flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC
open_flags = os.O_RDWR | os.O_TRUNC
if not Path(self.lock_file).exists():
open_flags |= os.O_CREAT
fd = os.open(self.lock_file, open_flags, self._context.mode)
with suppress(PermissionError): # This locked is not owned by this UID
os.fchmod(fd, self._context.mode)
Expand Down

0 comments on commit 9a64375

Please sign in to comment.