From f9b45e3d4dcd4b45c4205707c2fe4dc4ebe21478 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Thu, 11 Feb 2010 16:04:32 +0100 Subject: [PATCH] [entropy.security] improve System class advisories cache handling --- libraries/entropy/security.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/libraries/entropy/security.py b/libraries/entropy/security.py index ad6142663..c2020230c 100644 --- a/libraries/entropy/security.py +++ b/libraries/entropy/security.py @@ -536,6 +536,17 @@ class System: os.makedirs(System._CACHE_DIR, 0o775) const_setup_perms(System._CACHE_DIR, etpConst['entropygid']) + def _get_advisories_cache_hash(self): + dir_checksum = entropy.tools.md5sum_directory( + System.SECURITY_DIR) + c_hash = "%s%s" % ( + System._CACHE_ID, hash("%s|%s|%s" % ( + hash(self._settings['repositories']['branch']), + hash(dir_checksum), + hash(etpConst['systemroot']), + ),)) + return c_hash + def get_advisories_cache(self): """ Return cached advisories information metadata. It first tries to load @@ -548,15 +559,7 @@ class System: # validate cache self.__validate_cache() - dir_checksum = entropy.tools.md5sum_directory( - System.SECURITY_DIR) - c_hash = "%s%s" % ( - System._CACHE_ID, hash("%s|%s|%s" % ( - hash(self._settings['repositories']['branch']), - hash(dir_checksum), - hash(etpConst['systemroot']), - )), - ) + c_hash = self._get_advisories_cache_hash() adv_metadata = self.__cacher.pop(c_hash, cache_dir = System._CACHE_DIR) if adv_metadata is not None: @@ -570,15 +573,8 @@ class System: @param adv_metadata: advisories metadata to store @type adv_metadata: dict """ - dir_checksum = entropy.tools.md5sum_directory( - System.SECURITY_DIR) - c_hash = "%s%s" % ( - System._CACHE_ID, hash("%s|%s|%s" % ( - hash(self._settings['repositories']['branch']), - hash(dir_checksum), - hash(etpConst['systemroot']), - )), - ) + self.adv_metadata = None + c_hash = self._get_advisories_cache_hash() # async false to allow 3rd-party applications to not wait # before getting cached results. A straight example: sulfur # and its security cache generation separate thread.