live: clean files after a failed cache image copy

Remove image files after a failed image copy operation.
master
Alejandro Sirgo Rica 2024-08-08 16:11:26 +02:00
parent 73ecb48113
commit 9fa4a5f651
1 changed files with 7 additions and 0 deletions

View File

@ -208,6 +208,13 @@ class OgLiveOperations:
r = shutil.copy(src, dst)
tip_write_csum(image_name)
except (OSError, OgError) as e:
try:
if os.path.exists(dst):
os.unlink(dst)
if os.path.exists(f"{dst}.full.sum"):
os.unlink(f"{dst}.full.sum")
except OSError as e:
pass
raise OgError(f'Error copying image {image_name} to cache. Reported: {e}') from e
if (not os.path.exists(dst)):