Skip to content

Commit 9e4dfaf

Browse files
committed
fix(cli): fix data deletion of cleanup during download
1 parent 3711113 commit 9e4dfaf

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

cli/kleinkram/api/file_transfer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ def download_file(
457457
path.parent.mkdir(parents=True, exist_ok=True)
458458

459459
# download the file and check the hash
460+
had_prior_bytes = not overwrite and path.exists() and path.stat().st_size > 0
460461
try:
461462
_url_download(
462463
download_url,
@@ -471,7 +472,7 @@ def download_file(
471472
# If cancel was requested, treat as cancellation regardless of exception type
472473
if cancel_event is not None and cancel_event.is_set():
473474
logger.info(f"Download cancelled for {path}")
474-
if path.exists():
475+
if (not had_prior_bytes or overwrite) and path.exists():
475476
try:
476477
path.unlink()
477478
logger.info(f"Removed potentially incomplete file {path}")
@@ -480,8 +481,8 @@ def download_file(
480481
return DownloadState.CANCELED, 0
481482

482483
logger.error(f"Error during download of {path}: {e}")
483-
# Attempt to clean up potentially partial file
484-
if path.exists():
484+
# Only clean up files we created; preserve prior bytes for resume
485+
if (not had_prior_bytes or overwrite) and path.exists():
485486
try:
486487
path.unlink()
487488
logger.info(f"Removed potentially incomplete file {path}")

0 commit comments

Comments
 (0)