MCPcopy Create free account
hub / github.com/tox-dev/filelock / _acquire

Method _acquire

src/filelock/_windows.py:59–86  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

57 """
58
59 def _acquire(self) -> None:
60 raise_on_not_writable_file(self.lock_file)
61 ensure_directory_exists(self.lock_file)
62
63 # Security check: Refuse to open reparse points (symlinks, junctions)
64 # This prevents TOCTOU symlink attacks (CVE-TBD)
65 if _is_reparse_point(self.lock_file):
66 msg = f"Lock file is a reparse point (symlink/junction): {self.lock_file}"
67 raise OSError(msg)
68
69 flags = (
70 os.O_RDWR # open for read and write
71 | os.O_CREAT # create file if not exists
72 )
73 try:
74 fd = os.open(self.lock_file, flags, self._open_mode())
75 except OSError as exception:
76 if exception.errno != EACCES: # has no access to this lock
77 raise
78 else:
79 try:
80 msvcrt.locking(fd, msvcrt.LK_NBLCK, 1)
81 except OSError as exception:
82 os.close(fd) # close file first
83 if exception.errno != EACCES: # file is already locked
84 raise
85 else:
86 self._context.lock_file_fd = fd
87
88 def _release(self) -> None:
89 fd = cast("int", self._context.lock_file_fd)

Callers

nothing calls this directly

Calls 5

ensure_directory_existsFunction · 0.85
_is_reparse_pointFunction · 0.85
_open_modeMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected