summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/linux/ogOperations.py3
-rw-r--r--src/live/ogOperations.py40
-rw-r--r--src/ogRest.py18
-rw-r--r--src/restRequest.py7
-rw-r--r--src/virtual/ogOperations.py3
-rw-r--r--src/windows/ogOperations.py3
6 files changed, 74 insertions, 0 deletions
diff --git a/src/linux/ogOperations.py b/src/linux/ogOperations.py
index b71c4f4..7686956 100644
--- a/src/linux/ogOperations.py
+++ b/src/linux/ogOperations.py
@@ -55,6 +55,9 @@ class OgLinuxOperations:
def image_create(self, path, request, ogRest):
raise NotImplementedError
+ def cache_delete(self, request, ogRest):
+ raise NotImplementedError
+
def refresh(self, ogRest):
return {"status": "LINUX"}
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)
diff --git a/src/ogRest.py b/src/ogRest.py
index 5d6c746..ad57c8c 100644
--- a/src/ogRest.py
+++ b/src/ogRest.py
@@ -215,6 +215,19 @@ class ogThread():
client.send(response.get())
ogRest.state = ThreadState.IDLE
+ def cache_delete(client, request, ogRest):
+ try:
+ out = ogRest.operations.cache_delete(request, ogRest)
+ except Exception as e:
+ ogRest.send_internal_server_error(client, exc=e)
+ return
+
+ json_body = jsonBody(out)
+
+ response = restResponse(ogResponses.OK, json_body, seq=client.seq)
+ client.send(response.get())
+ ogRest.state = ThreadState.IDLE
+
def refresh(client, ogRest):
try:
out = ogRest.operations.refresh(ogRest)
@@ -328,6 +341,8 @@ class ogRest():
self.process_stop(client)
elif ("image/create" in URI):
self.process_imagecreate(client, request)
+ elif ("cache/delete" in URI):
+ self.process_cache_delete(client, request)
else:
logging.warn('Unsupported request: %s',
URI[:ogRest.LOG_LENGTH])
@@ -430,5 +445,8 @@ class ogRest():
def process_imagecreate(self, client, request):
threading.Thread(target=ogThread.image_create, args=(client, request, self,)).start()
+ def process_cache_delete(self, client, request):
+ threading.Thread(target=ogThread.cache_delete, args=(client, request, self,)).start()
+
def process_refresh(self, client):
threading.Thread(target=ogThread.refresh, args=(client, self,)).start()
diff --git a/src/restRequest.py b/src/restRequest.py
index 8128b08..fdfe633 100644
--- a/src/restRequest.py
+++ b/src/restRequest.py
@@ -37,6 +37,7 @@ class restRequest:
self.code = None
self.seq = None
self.backup = None
+ self.images = None
def parser(self,data):
self.request_line, self.headers_alone = data.split('\n', 1)
@@ -75,6 +76,9 @@ class restRequest:
except:
pass
+ if "images" in json_param:
+ self.images = json_param["images"]
+
if "disk" in json_param:
self.disk = json_param["disk"]
@@ -114,6 +118,9 @@ class restRequest:
def get_method(self):
return self.method
+ def getImages(self):
+ return self.images
+
def get_uri(self):
return self.URI
diff --git a/src/virtual/ogOperations.py b/src/virtual/ogOperations.py
index 3cfe83a..2b69fd1 100644
--- a/src/virtual/ogOperations.py
+++ b/src/virtual/ogOperations.py
@@ -458,6 +458,9 @@ class OgVirtualOperations:
return True
+ def cache_delete(self, request, ogRest):
+ raise NotImplementedError
+
def software(self, request, path, ogRest):
DPKG_PATH = '/var/lib/dpkg/status'
diff --git a/src/windows/ogOperations.py b/src/windows/ogOperations.py
index d20b52c..70d3c5b 100644
--- a/src/windows/ogOperations.py
+++ b/src/windows/ogOperations.py
@@ -110,6 +110,9 @@ class OgWindowsOperations:
def image_create(self, path, request, ogRest):
raise NotImplementedError
+ def cache_delete(self, request, ogRest):
+ raise NotImplementedError
+
def refresh(self, ogRest):
return {"status": "WIN"}