From 8de2b785a9be79f9cc0caa0011293f95a42d4d31 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Thu, 23 May 2024 11:17:35 +0200 Subject: src: add POST cache/delete method Add API REST method to delete cache contents. Resquest payload structure: { 'images': ['windows.img', 'linux.img'] } The client will try to delete as many images in cache as available with names matching the list of filenames in the 'images' field. Resquest response structure: { 'cache': [ {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'}, {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'} ] } --- src/live/ogOperations.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/live') diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py index 6948d98..d557fac 100644 --- a/src/live/ogOperations.py +++ b/src/live/ogOperations.py @@ -576,6 +576,46 @@ class OgLiveOperations: logging.info('Image creation command OK') return image_info + def cache_delete(self, request, ogRest): + images = request.getImages() + deleted_images = [] + + if not mount_cache(): + return + + img_dir = OG_CACHE_IMAGE_PATH + + if not os.path.isdir(img_dir): + return cache_contents + + for file_name in os.listdir(img_dir): + file_path = os.path.join(img_dir, file_name) + + if not os.path.isfile(file_path): + continue + if not file_name.endswith('.img'): + continue + if os.sep in file_name: + logging.info(f'Detected cache deletion request of filename with a path, ignoring {file_name}') + continue + + if file_name in images: + os.remove(file_path) + + csum_path = file_path + '.full.sum' + if not os.path.isfile(csum_path): + logging.info(f'Missing checksum file for {file_path}') + continue + + os.remove(csum_path) + + result = {'cache': self._get_cache_contents()} + + self._restartBrowser(self._url) + + logging.info('Sending response to cache/delete request') + return result + def refresh(self, ogRest): self._restartBrowser(self._url_log) -- cgit v1.2.3-18-g5258