summaryrefslogtreecommitdiffstats
path: root/src/utils/tiptorrent.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/tiptorrent.py')
-rw-r--r--src/utils/tiptorrent.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/utils/tiptorrent.py b/src/utils/tiptorrent.py
index 77cc78b..932f164 100644
--- a/src/utils/tiptorrent.py
+++ b/src/utils/tiptorrent.py
@@ -41,6 +41,16 @@ def tip_fetch_csum(tip_addr, image_name):
return r
+def _tip_read_csum(image_checksum_path):
+ try:
+ with open(image_checksum_path, 'r') as f:
+ checksum = f.read().strip("\n")
+ except OSError as e:
+ return "unavailable"
+
+ return checksum
+
+
def tip_write_csum(image_name):
if not mount_cache():
raise OgError(f'Failed to checksum {image_name}: cache partition is not available')
@@ -71,13 +81,12 @@ def tip_check_csum(tip_addr, image_name):
image_path = f'{OG_CACHE_IMAGE_PATH}{image_name}.img'
if not os.path.exists(image_path):
raise OgError(f'File {image_path} does not exist')
-
- cache_csum = _compute_md5(image_path)
- remote_csum = tip_fetch_csum(tip_addr, image_name)
-
if not os.path.exists(f"{image_path}.full.sum"):
raise OgError(f'File {image_path}.full.sum does not exist in repository {tip_addr}')
+ cache_csum = _tip_read_csum(f"{image_path}.full.sum")
+ remote_csum = tip_fetch_csum(tip_addr, image_name)
+
if cache_csum == remote_csum:
ret = True
logging.info(f'Checksum is OK for {image_name}.img')