From 74993fa2e149db6e056ceec98fe52f289573a6dc Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 10 Aug 2013 11:19:22 +0200 Subject: [PATCH] [entropy.client] _generate_reverse_dependency_tree: rewrite cache key generation code We now rely on SHA1 rather than hash() and string magic, which is likely to give us a lot more collisions. --- lib/entropy/client/interfaces/dep.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/entropy/client/interfaces/dep.py b/lib/entropy/client/interfaces/dep.py index 2655b234a..e0abfe13d 100644 --- a/lib/entropy/client/interfaces/dep.py +++ b/lib/entropy/client/interfaces/dep.py @@ -2315,14 +2315,20 @@ class CalculatorsMixin: for x in matched_atoms], deep, recursive, empty, system_packages, elf_needed_scanning)) - c_hash = "%s%s" % ( - EntropyCacher.CACHE_IDS['depends_tree'], - hash("%s|%s|%s|%s|%s|%s" % (tuple(sorted(matched_atoms)), deep, - recursive, empty, system_packages, elf_needed_scanning,), - ), - ) + cache_key = None if self.xcache: - cached = self._cacher.pop(c_hash) + sha = hashlib.sha1() + + cache_s = "ma{%s}s{%s;%s;%s;%s;%s}" % ( + ";".join(sorted(matched_atoms)), deep, + recursive, empty, system_packages, + elf_needed_scanning,) + sha.update(const_convert_to_rawstring(cache_s)) + + cache_key = "%s%s" % ( + EntropyCacher.CACHE_IDS['depends_tree'], sha.hexdigest(),) + + cached = self._cacher.pop(cache_key) if cached is not None: return cached @@ -2717,8 +2723,9 @@ class CalculatorsMixin: graph.destroy() - if self.xcache: - self._cacher.push(c_hash, deptree) + if cache_key is not None: + self._cacher.push(cache_key, deptree) + return deptree def calculate_masked_packages(self, use_cache = True):