MCPcopy
hub / github.com/httpie/cli / open_with_lockfile

Function open_with_lockfile

httpie/utils.py:275–290  ·  view source on GitHub ↗
(file: Path, *args, **kwargs)

Source from the content-addressed store, hash-verified

273
274@contextmanager
275def 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
293def is_version_greater(version_1: str, version_2: str) -> bool:

Callers 3

_fetch_updatesFunction · 0.90
_get_update_statusFunction · 0.90
check_updatesFunction · 0.90

Calls 3

PathClass · 0.85
LockFileErrorClass · 0.85
decodeMethod · 0.80

Tested by

no test coverage detected