summaryrefslogtreecommitdiffstats
path: root/src/live/ogOperations.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/live/ogOperations.py')
-rw-r--r--src/live/ogOperations.py55
1 files changed, 39 insertions, 16 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index 9cc5b97..b22d8b2 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -178,14 +178,21 @@ class OgLiveOperations:
return 0
- def _copy_image_to_cache(self, image_name):
+ def _fetch_image_unicast(self, repo, image_name):
"""
Copies /opt/opengnsys/image/{image_name} into
/opt/opengnsys/cache/opt/opengnsys/images/
Implies a unicast transfer. Does not use tiptorrent.
"""
+ if not get_cache_dev_path():
+ raise OgError('No cache partition is mounted')
+
dst = f'{OG_CACHE_IMAGE_PATH}{image_name}.img'
+
+ if (os.path.exists(dst) and tip_check_csum(repo, image_name)):
+ return
+
try:
if os.path.exists(dst):
os.unlink(dst)
@@ -203,26 +210,19 @@ class OgLiveOperations:
except (OSError, OgError) as e:
raise OgError(f'Error copying image {image_name} to cache. Reported: {e}') from e
+ if (not os.path.exists(dst)):
+ raise OgError(f'could not find {dst} in cache')
+ if (not tip_check_csum(repo, image_name)):
+ raise OgError(f'Failed to validate checksum for {image_name}.img')
+
def _restore_image_unicast(self, repo, name, devpath, cache=False):
if ogChangeRepo(repo, smb_user=self._smb_user, smb_pass=self._smb_pass) != 0:
self._restartBrowser(self._url)
raise OgError(f'Cannot change repository to {repo}')
if cache:
- if not get_cache_dev_path():
- raise OgError('No cache partition is mounted')
-
- fetch = False
- image_path = f'{OG_CACHE_IMAGE_PATH}{name}.img'
- if (not os.path.exists(image_path) or not tip_check_csum(repo, name)):
- self._copy_image_to_cache(name)
- fetch = True
-
- if fetch:
- if (not os.path.exists(image_path)):
- raise OgError(f'could not find {image_path} in cache')
- if (not tip_check_csum(repo, name)):
- raise OgError(f'Failed to validate checksum for {name}.img')
+ self._fetch_image_unicast(repo, name)
+ image_path = f'{OG_CACHE_IMAGE_PATH}{image_name}.img'
else:
if os.access(f'/opt/opengnsys/images', os.R_OK) == False:
raise OgError('Cannot access /opt/opengnsys/images in read mode, check permissions')
@@ -232,7 +232,7 @@ class OgLiveOperations:
self._restore_image(image_path, devpath)
- def _restore_image_tiptorrent(self, repo, name, devpath):
+ def _fetch_image_tiptorrent(self, repo, name):
if not get_cache_dev_path():
raise OgError('No cache partition is mounted')
@@ -251,7 +251,10 @@ class OgLiveOperations:
raise OgError(f'could not find {image_path} in cache')
if (not tip_check_csum(repo, name)):
raise OgError(f'Failed to validate checksum for {name}.img')
+ return image_path
+ def _restore_image_tiptorrent(self, repo, name, devpath):
+ image_path = self._fetch_image_tiptorrent(repo, name)
self._restore_image(image_path, devpath)
def _restore_image(self, image_path, devpath):
@@ -677,6 +680,26 @@ class OgLiveOperations:
logging.info('Delete file from cache request OK')
return result
+ def cache_fetch(self, request, ogRest):
+ image = request.getImages()
+ repo = request.getRepo()
+ ctype = request.getType()
+
+ logging.info(f'Request to cache image {image}.img via {ctype} from {repo}')
+
+ if ctype == 'UNICAST':
+ self._fetch_image_unicast(repo, image)
+ elif ctype == 'TIPTORRENT':
+ self._fetch_image_tiptorrent(repo, image)
+ else:
+ raise OgError(f'Invalid image fetch type {ctype}')
+
+ logging.info('Cache fetch command OK')
+
+ result = {'cache': self._get_cache_contents()}
+
+ return result
+
def refresh(self, ogRest):
self._restartBrowser(self._url_log)