From bb4c47bd265036d103cae496fae1977ebffec605 Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Mon, 2 Dec 2024 16:30:43 +0200 Subject: [PATCH] container: Factor out loading an image tarball --- dangerzone/isolation_provider/container.py | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/dangerzone/isolation_provider/container.py b/dangerzone/isolation_provider/container.py index 1277064c4..068b5d813 100644 --- a/dangerzone/isolation_provider/container.py +++ b/dangerzone/isolation_provider/container.py @@ -223,16 +223,14 @@ def add_image_tag(cur_tag: str, new_tag: str) -> None: ) @staticmethod - def install() -> bool: - """ - Make sure the podman container is installed. Linux only. - """ - if Container.is_container_installed(): - return True + def get_expected_tag() -> str: + """Get the tag of the Dangerzone image tarball from the image-id.txt file.""" + with open(get_resource_path("image-id.txt")) as f: + return f.read.strip() - # Load the container into podman + @staticmethod + def load_image_tarball() -> None: log.info("Installing Dangerzone container image...") - p = subprocess.Popen( [Container.get_runtime(), "load"], stdin=subprocess.PIPE, @@ -259,6 +257,18 @@ def install() -> bool: f"Could not install container image: {error}" ) + log.info("Successfully installed container image from") + + @staticmethod + def install() -> bool: + """ + Make sure the podman container is installed. Linux only. + """ + if Container.is_container_installed(): + return True + + Container.load_image_tarball() + if not Container.is_container_installed(raise_on_error=True): return False