From d9d0606fe01618cc81fb0b862ada91149dad3746 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 3 Oct 2011 02:42:53 -0700 Subject: GLEP 59: use manifest-hashes list in layout.conf The manifest-hashes layout.conf setting simply overrides the hashes that are generated. When unspecified, the MANIFEST2_HASH_DEFAULTS constant is used instead (current value contains SHA1, SHA256, and RMD160). In order to enable SHA512 and WHIRLPOOL, and drop RMD160 and SHA1, simply set "manifest-hashes = SHA256 SHA512 WHIRLPOOL" in layout.conf. As with the previous boolean flags approach, manifest-hashes settings become redundant and can be removed from layout.conf after a version of portage with equivalent defaults is stable. --- pym/portage/const.py | 11 +++++++---- pym/portage/manifest.py | 14 +++++--------- pym/portage/repository/config.py | 25 +++++++------------------ 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/pym/portage/const.py b/pym/portage/const.py index e7eac62fb..e3627ea6e 100644 --- a/pym/portage/const.py +++ b/pym/portage/const.py @@ -114,20 +114,23 @@ MANIFEST1_REQUIRED_HASH = "MD5" # Future events: # # After WHIRLPOOL is supported in stable portage: -# - Add WHIRLPOOL to MANIFEST2_HASH_DEFAULTS. +# - Add SHA256 and WHIRLPOOL to MANIFEST2_HASH_DEFAULTS. # - Remove SHA1 and RMD160 from MANIFEST2_HASH_*. -# - Toggle gentoo-x86/metadata/layout.conf settings to match. +# - Set manifest-hashes in gentoo-x86/metadata/layout.conf as follows: +# manifest-hashes = SHA256 SHA512 WHIRLPOOL # # After WHIRLPOOL is supported in stable portage for at least 1 year: # - Change MANIFEST2_REQUIRED_HASH to WHIRLPOOL. # - Remove SHA256 from MANIFEST2_HASH_*. -# - Toggle gentoo-x86/metadata/layout.conf settings to match. +# - Set manifest-hashes in gentoo-x86/metadata/layout.conf as follows: +# manifest-hashes = SHA512 WHIRLPOOL # # After SHA-3 is approved: # - Add new hashes to MANIFEST2_HASH_*. # # After SHA-3 is supported in stable portage: -# - Toggle gentoo-x86/metadata/layout.conf settings to match. +# - Set manifest-hashes in gentoo-x86/metadata/layout.conf as follows: +# manifest-hashes = SHA3 SHA512 WHIRLPOOL # # After layout.conf settings correspond to defaults in stable portage: # - Remove redundant settings from gentoo-x86/metadata/layout.conf. diff --git a/pym/portage/manifest.py b/pym/portage/manifest.py index eaea0bdf6..78153c02a 100644 --- a/pym/portage/manifest.py +++ b/pym/portage/manifest.py @@ -103,7 +103,7 @@ class Manifest(object): parsers = (parseManifest2,) def __init__(self, pkgdir, distdir, fetchlist_dict=None, manifest1_compat=DeprecationWarning, from_scratch=False, thin=False, - allow_missing=False, allow_create=True, hash_flags=None): + allow_missing=False, allow_create=True, hashes=None): """ Create new Manifest instance for package in pkgdir. Do not parse Manifest file if from_scratch == True (only for internal use) The fetchlist_dict parameter is required only for generation of @@ -120,14 +120,10 @@ class Manifest(object): self.fhashdict = {} self.hashes = set() - if hash_flags is None: - hash_flags = {} - self.hash_flags = hash_flags - for hash_type in MANIFEST2_HASH_FUNCTIONS: - default_state = hash_type in MANIFEST2_HASH_DEFAULTS - if hash_flags.get(hash_type, default_state): - self.hashes.add(hash_type) + if hashes is None: + hashes = MANIFEST2_HASH_DEFAULTS + self.hashes.update(hashes.intersection(MANIFEST2_HASH_FUNCTIONS)) self.hashes.difference_update(hashname for hashname in \ list(self.hashes) if hashname not in hashfunc_map) self.hashes.add("size") @@ -360,7 +356,7 @@ class Manifest(object): self.__init__(self.pkgdir, self.distdir, fetchlist_dict=self.fetchlist_dict, from_scratch=True, thin=self.thin, allow_missing=self.allow_missing, - allow_create=self.allow_create, hash_flags=self.hash_flags) + allow_create=self.allow_create, hashes=self.hashes) pn = os.path.basename(self.pkgdir.rstrip(os.path.sep)) cat = self._pkgdir_category() diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py index c201fe751..779d432be 100644 --- a/pym/portage/repository/config.py +++ b/pym/portage/repository/config.py @@ -44,7 +44,7 @@ class RepoConfig(object): __slots__ = ['aliases', 'eclass_overrides', 'eclass_locations', 'location', 'user_location', 'masters', 'main_repo', 'missing_repo_name', 'name', 'priority', 'sync', 'format', 'sign_manifest', 'thin_manifest', 'allow_missing_manifest', 'create_manifest', 'disable_manifest', 'cache_is_authoritative', - 'trust_authoritative_cache', 'manifest_hash_flags'] + 'trust_authoritative_cache', 'manifest_hashes'] def __init__(self, name, repo_opts): """Build a RepoConfig with options in repo_opts @@ -118,7 +118,7 @@ class RepoConfig(object): self.allow_missing_manifest = False self.create_manifest = True self.disable_manifest = False - self.manifest_hash_flags = {} + self.manifest_hashes = None self.cache_is_authoritative = False @@ -131,7 +131,7 @@ class RepoConfig(object): kwds['thin'] = self.thin_manifest kwds['allow_missing'] = self.allow_missing_manifest kwds['allow_create'] = self.create_manifest - kwds['hash_flags'] = self.manifest_hash_flags + kwds['hashes'] = self.manifest_hashes if self.disable_manifest: kwds['from_scratch'] = True return manifest.Manifest(*args, **kwds) @@ -382,21 +382,10 @@ class RepoConfigLoader(object): repo.create_manifest = manifest_policy != 'false' repo.disable_manifest = manifest_policy == 'false' - if 'manifest-rmd160' in layout_data: - repo.manifest_hash_flags["RMD160"] = \ - layout_data['manifest-rmd160'].lower() == 'true' - - if 'manifest-sha1' in layout_data: - repo.manifest_hash_flags["SHA1"] = \ - layout_data['manifest-sha1'].lower() == 'true' - - if 'manifest-sha256' in layout_data: - repo.manifest_hash_flags["SHA256"] = \ - layout_data['manifest-sha256'].lower() == 'true' - - if 'manifest-whirlpool' in layout_data: - repo.manifest_hash_flags["WHIRLPOOL"] = \ - layout_data['manifest-whirlpool'].lower() == 'true' + manifest_hashes = layout_data.get('manifest-hashes') + if manifest_hashes is not None: + manifest_hashes = frozenset(manifest_hashes.upper().split()) + repo.manifest_hashes = manifest_hashes repo.cache_is_authoritative = layout_data.get('authoritative-cache', 'false').lower() == 'true' if not repo.trust_authoritative_cache: -- cgit v1.2.3-1-g7c22