From f98edaff58e7339a885addc1d443677718bc20f3 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Wed, 31 Oct 2018 08:07:58 +0100 Subject: [PATCH] Fix appmgr metadata fetching logic --- basic/srv/vm/mgr/appmgr.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/basic/srv/vm/mgr/appmgr.py b/basic/srv/vm/mgr/appmgr.py index 289dd44..b7b7ea7 100644 --- a/basic/srv/vm/mgr/appmgr.py +++ b/basic/srv/vm/mgr/appmgr.py @@ -54,13 +54,15 @@ class AppMgr: def fetch_online_packages(self): # Fetches and verifies online packages. Can raise InvalidSignature - self.online_packages = {} + online_packages = {} packages = self.get_repo_resource('packages').content packages_sig = self.get_repo_resource('packages.sig').content with open(PUB_FILE, 'rb') as f: pub_key = load_pem_public_key(f.read(), default_backend()) pub_key.verify(packages_sig, packages, ec.ECDSA(hashes.SHA512())) - self.online_packages = json.loads(packages) + online_packages = json.loads(packages) + # Minimze the time when self.online_packages is out of sync + self.online_packages = online_packages def enqueue_action(self, action, app): # Remove actions older than 1 day @@ -110,7 +112,7 @@ class AppMgr: for dep in deps: item.data.stage = 1 # Purge old data before unpacking to clean previous failed installation - self.purge_package() + self.purge_package(dep) self.unpack_package(dep) for deps in deps: item.data.stage = 3 if dep == deps[-1] else 2 @@ -147,7 +149,8 @@ class AppMgr: def purge_package(self, name): # Removes package and shared data from filesystem - lxc_dir = os.path.join(LXC_ROOT, self.conf['packages'][name]['lxcpath']) + lxcpath = self.conf['packages'][name]['lxcpath'] if name in self.conf['packages'] else self.online_packages[name]['lxcpath'] + lxc_dir = os.path.join(LXC_ROOT, lxcpath) if os.path.exists(lxc_dir): shutil.rmtree(lxc_dir) srv_dir = os.path.join('/srv/', name)