(file: Path, *args, **kwargs)
| 273 | |
| 274 | @contextmanager |
| 275 | def open_with_lockfile(file: Path, *args, **kwargs) -> Generator[IO[Any], None, None]: |
| 276 | file_id = base64.b64encode(os.fsencode(file)).decode() |
| 277 | target_file = Path(tempfile.gettempdir()) / file_id |
| 278 | |
| 279 | # Have an atomic-like touch here, so we'll tighten the possibility of |
| 280 | # a race occurring between multiple processes accessing the same file. |
| 281 | try: |
| 282 | target_file.touch(exist_ok=False) |
| 283 | except FileExistsError as exc: |
| 284 | raise LockFileError("Can't modify a locked file.") from exc |
| 285 | |
| 286 | try: |
| 287 | with open(file, *args, **kwargs) as stream: |
| 288 | yield stream |
| 289 | finally: |
| 290 | target_file.unlink() |
| 291 | |
| 292 | |
| 293 | def is_version_greater(version_1: str, version_2: str) -> bool: |
no test coverage detected