summaryrefslogtreecommitdiffstats
path: root/pym/portage/checksum.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2012-08-21 13:22:19 -0700
committerZac Medico <zmedico@gentoo.org>2012-08-21 13:22:19 -0700
commitaccee1b7c61da284022f86d9ab39bcb492ea4023 (patch)
tree7a25fa56dbb0b3878f5a8050f60f0a193281057b /pym/portage/checksum.py
parentb696337bf20fdc539ce7721df7a4b42b35999705 (diff)
downloadportage-accee1b7c61da284022f86d9ab39bcb492ea4023.tar.gz
portage-accee1b7c61da284022f86d9ab39bcb492ea4023.tar.bz2
portage-accee1b7c61da284022f86d9ab39bcb492ea4023.zip
Implement PORTAGE_CHECKSUM_FILTER for bug #432170
Diffstat (limited to 'pym/portage/checksum.py')
-rw-r--r--pym/portage/checksum.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/pym/portage/checksum.py b/pym/portage/checksum.py
index daf4a0cbf..de4cc668a 100644
--- a/pym/portage/checksum.py
+++ b/pym/portage/checksum.py
@@ -217,6 +217,60 @@ def _filter_unaccelarated_hashes(digests):
return digests
+class _hash_filter(object):
+ """
+ Implements filtering for PORTAGE_CHECKSUM_FILTER.
+ """
+
+ __slots__ = ('transparent', '_tokens',)
+
+ def __init__(self, filter_str):
+ tokens = filter_str.upper().split()
+ if not tokens or tokens[-1] == "*":
+ del tokens[:]
+ self.transparent = not tokens
+ tokens.reverse()
+ self._tokens = tuple(tokens)
+
+ def __call__(self, hash_name):
+ if self.transparent:
+ return True
+ matches = ("*", hash_name)
+ for token in self._tokens:
+ if token in matches:
+ return True
+ elif token[:1] == "-":
+ if token[1:] in matches:
+ return False
+ return False
+
+def _apply_hash_filter(digests, hash_filter):
+ """
+ Return a new dict containing the filtered digests, or the same
+ dict if no changes are necessary. This will always preserve at
+ at least one digest, in order to ensure that they are not all
+ discarded.
+ """
+ if hash_filter.transparent:
+ return digests
+
+ verifiable_hash_types = set(digests).intersection(hashfunc_map)
+ verifiable_hash_types.discard("size")
+ modified = False
+ if len(verifiable_hash_types) > 1:
+ for k in list(verifiable_hash_types):
+ if not hash_filter(k):
+ modified = True
+ verifiable_hash_types.remove(k)
+ if len(verifiable_hash_types) == 1:
+ break
+
+ if modified:
+ digests = dict((k, v) for (k, v) in digests.items()
+ if k == "size" or k in verifiable_hash_types)
+
+ return digests
+
def verify_all(filename, mydict, calc_prelink=0, strict=0):
"""
Verify all checksums against a file.