diff options
Diffstat (limited to 'packages/meshbay-cli/src/meshbay_cli/client/transfers.py')
| -rw-r--r-- | packages/meshbay-cli/src/meshbay_cli/client/transfers.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/packages/meshbay-cli/src/meshbay_cli/client/transfers.py b/packages/meshbay-cli/src/meshbay_cli/client/transfers.py index 2cbf4cd..177c78b 100644 --- a/packages/meshbay-cli/src/meshbay_cli/client/transfers.py +++ b/packages/meshbay-cli/src/meshbay_cli/client/transfers.py @@ -128,7 +128,8 @@ class Resume: sidecar = target.with_name(target.name + PART_SUFFIX + ".json") done = 0 try: - meta = json.loads(sidecar.read_text(encoding="utf-8")) + with open(long_path(sidecar), encoding="utf-8") as f: + meta = json.load(f) if meta.get("id") == entry["id"] and meta.get("size") == entry["size"]: # Every chunk but the last is whole, so the complete ones are # what the part's length says. @@ -198,8 +199,8 @@ def _prepare_part(resume: Resume, entry: dict, start: int) -> None: pass else: os.truncate(part, start * DOWNLOAD_CHUNK) - resume.sidecar.write_text(json.dumps({"id": entry["id"], "size": entry["size"]}), - encoding="utf-8") + with open(long_path(resume.sidecar), "w", encoding="utf-8") as f: + json.dump({"id": entry["id"], "size": entry["size"]}, f) def _publish(resume: Resume, target: Path, overwrite: bool) -> None: @@ -220,7 +221,7 @@ def _publish(resume: Resume, target: Path, overwrite: bool) -> None: raise TransferError(f"{target} already exists.") from None os.replace(part, dest) with contextlib.suppress(OSError): - resume.sidecar.unlink() + os.unlink(long_path(resume.sidecar)) if sys.platform == "win32": mark_of_the_web(target) |