(self)
| 33 | """ |
| 34 | |
| 35 | def _acquire(self) -> None: |
| 36 | raise_on_not_writable_file(self.lock_file) |
| 37 | ensure_directory_exists(self.lock_file) |
| 38 | flags = ( |
| 39 | os.O_WRONLY # open for writing only |
| 40 | | os.O_CREAT |
| 41 | | os.O_EXCL # together with above raise EEXIST if the file specified by filename exists |
| 42 | | os.O_TRUNC # truncate the file to zero byte |
| 43 | ) |
| 44 | if (o_nofollow := getattr(os, "O_NOFOLLOW", None)) is not None: |
| 45 | flags |= o_nofollow |
| 46 | try: |
| 47 | file_handler = os.open(self.lock_file, flags, self._open_mode()) |
| 48 | except OSError as exception: |
| 49 | if not ( |
| 50 | exception.errno == EEXIST or (exception.errno == EACCES and sys.platform == "win32") |
| 51 | ): # pragma: win32 no cover |
| 52 | raise |
| 53 | self._try_break_stale_lock() |
| 54 | else: |
| 55 | self._write_lock_info(file_handler) |
| 56 | self._context.lock_file_fd = file_handler |
| 57 | |
| 58 | def _try_break_stale_lock(self) -> None: |
| 59 | with suppress(OSError, ValueError): |
nothing calls this directly
no test coverage detected