We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
/tmp
1 parent e2f121b commit 9a64375Copy full SHA for 9a64375
src/filelock/_unix.py
@@ -4,6 +4,7 @@
4
import sys
5
from contextlib import suppress
6
from errno import ENOSYS
7
+from pathlib import Path
8
from typing import cast
9
10
from ._api import BaseFileLock
@@ -35,7 +36,9 @@ class UnixFileLock(BaseFileLock):
35
36
37
def _acquire(self) -> None:
38
ensure_directory_exists(self.lock_file)
- 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
42
fd = os.open(self.lock_file, open_flags, self._context.mode)
43
with suppress(PermissionError): # This locked is not owned by this UID
44
os.fchmod(fd, self._context.mode)
0 commit comments