diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-07-30 00:14:01 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-07-30 16:11:40 +0200 |
commit | 49017c00caa56255a6946003fd8a62804d6c061f (patch) | |
tree | 05ebdda9630b387ed840ec75bbc866b1165b35eb /src | |
parent | a846d5e34352cf7591c39c7c884a140acfc5ec78 (diff) |
utils: tip_check_csum() uses local checksum file
.full.sum file in the local cache contains the local checksum for this file,
this checksum is calculated by tip_write_csum(), therefore, there is no need to
calculate this checksum again from the image file in the cache, use this
checksum content instead.
if .full.sum is not available, then cache is inconsistent, tip_check_csum()
is called after checking if image file exists, raise an exception.
checksum could mismatch in two situations:
a) new image version (checksum is different)
b) image is corrupted
in both cases, a new fresh image needs to be retrieved.
this speeds up checksum validation.
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/tiptorrent.py | 17 |
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') |