summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-07-30 09:30:44 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-07-30 16:11:43 +0200
commit1376b1900d6bda4cbf7c9082e7cd201f6abcbab0 (patch)
treed4e2540ef9c7d4ebab794b9e7fbd4004ea90c9a4
parent49017c00caa56255a6946003fd8a62804d6c061f (diff)
live: remove old image and checksum file on download
Restoring an updated image file (with different checksum) could fail while the old checksum file could remain in place. Remove image and checksum file before fetching the new files.
-rw-r--r--src/live/ogOperations.py10
-rw-r--r--src/utils/tiptorrent.py6
2 files changed, 15 insertions, 1 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index 7bb2528..d77fe65 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -185,9 +185,17 @@ class OgLiveOperations:
Implies a unicast transfer. Does not use tiptorrent.
"""
- src = f'/opt/opengnsys/images/{image_name}.img'
dst = f'{OG_CACHE_IMAGE_PATH}{image_name}.img'
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:
+ raise OgError(f"Error deleting file {e.filename}: {e.strerror}") from e
+
+ src = f'/opt/opengnsys/images/{image_name}.img'
+ try:
logging.info(f'Fetching image {image_name} from {src}')
logging.info('*DO NOT REBOOT OR POWEROFF* the client during this time')
r = shutil.copy(src, dst)
diff --git a/src/utils/tiptorrent.py b/src/utils/tiptorrent.py
index 932f164..14ede8b 100644
--- a/src/utils/tiptorrent.py
+++ b/src/utils/tiptorrent.py
@@ -101,6 +101,12 @@ def tip_check_csum(tip_addr, image_name):
def tip_client_get(tip_addr, image_name):
"""
"""
+ image_path = f"{OG_CACHE_IMAGE_PATH}{image_name}.img"
+ if os.path.exists(image_path):
+ os.unlink(image_path)
+ if os.path.exists(f"{image_path}.full.sum"):
+ os.unlink(f"{image_path}.full.sum")
+
logging.info(f'Fetching image {image_name} from tiptorrent server at {tip_addr}')
logging.info('*DO NOT REBOOT OR POWEROFF* the client during this time')
cmd = f'tiptorrent-client {tip_addr} {image_name}.img'