From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 0516B158020 for ; Mon, 17 Oct 2022 19:37:24 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4377BE08FE; Mon, 17 Oct 2022 19:37:23 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0ACE2E08FE for ; Mon, 17 Oct 2022 19:37:23 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 47789340FFB for ; Mon, 17 Oct 2022 19:37:22 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 89844615 for ; Mon, 17 Oct 2022 19:37:20 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1666035436.bd0b901ff3024fbb2289b370bde475b4b435294c.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/, lib/portage/tests/util/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/manifest.py lib/portage/tests/util/test_manifest.py X-VCS-Directories: lib/portage/ lib/portage/tests/util/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: bd0b901ff3024fbb2289b370bde475b4b435294c X-VCS-Branch: master Date: Mon, 17 Oct 2022 19:37:20 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 21c6100f-5e58-4b04-be1f-7ff9ecb31e44 X-Archives-Hash: 988baf261525974eb73db6e57aed75fd commit: bd0b901ff3024fbb2289b370bde475b4b435294c Author: Sam James gentoo org> AuthorDate: Fri Oct 7 19:14:28 2022 +0000 Commit: Sam James gentoo org> CommitDate: Mon Oct 17 19:37:16 2022 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=bd0b901f portage: manifest: fix Manifest.addFile() call to renamed updateFileHashes Bug: https://bugs.gentoo.org/875860 Fixes: 5ac2a8f08101501d0416ad9d79e277c363cea85e Fixes: 64d84ce2d9a333e83e2a5fba5e7ec95f936959e7 Closes: https://github.com/gentoo/portage/pull/921 Signed-off-by: Sam James gentoo.org> lib/portage/manifest.py | 16 ++++++++-------- lib/portage/tests/util/test_manifest.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/lib/portage/manifest.py b/lib/portage/manifest.py index 65dda211b..6c0968415 100644 --- a/lib/portage/manifest.py +++ b/lib/portage/manifest.py @@ -464,21 +464,21 @@ class Manifest: def addFile(self, ftype, fname, hashdict=None, ignoreMissing=False): """Add entry to Manifest optionally using hashdict to avoid recalculation of hashes""" - if ftype == "AUX": - if not fname.startswith("files/"): - fname = os.path.join("files", fname) - if fname.startswith("files"): - fname = fname[6:] + if ftype == "AUX" and not fname.startswith("files/"): + fname = os.path.join("files", fname) if not os.path.exists(f"{self.pkgdir}{fname}") and not ignoreMissing: raise FileNotFound(fname) if ftype not in MANIFEST2_IDENTIFIERS: raise InvalidDataType(ftype) + + if fname.startswith("files"): + fname = fname[6:] self.fhashdict[ftype][fname] = {} if hashdict is not None: self.fhashdict[ftype][fname].update(hashdict) if self.required_hashes.difference(set(self.fhashdict[ftype][fname])): - self.updateFileHashes( - ftype, fname, checkExisting=False, ignoreMissing=ignoreMissing + self.updateAllFileHashes( + ftype, [fname], checkExisting=False, ignoreMissing=ignoreMissing ) def removeFile(self, ftype, fname): @@ -775,7 +775,7 @@ class Manifest: def updateHashesGuessType(self, fname, *args, **kwargs): """Regenerate hashes for the given file (guesses the type and then - calls updateFileHashes).""" + calls updateAllFileHashes).""" mytype = self.guessType(fname) if mytype is None: return diff --git a/lib/portage/tests/util/test_manifest.py b/lib/portage/tests/util/test_manifest.py new file mode 100644 index 000000000..49bcbc1a5 --- /dev/null +++ b/lib/portage/tests/util/test_manifest.py @@ -0,0 +1,31 @@ +# Copyright 2022 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +import tempfile + +from pathlib import Path +from portage import Manifest +from portage.tests import TestCase + + +class ManifestTestCase(TestCase): + def test_simple_addFile(self): + tempdir = Path(tempfile.mkdtemp()) / "app-portage" / "diffball" + manifest = Manifest(str(tempdir), required_hashes=["SHA512", "BLAKE2B"]) + + (tempdir / "files").mkdir(parents=True) + (tempdir / "files" / "test.patch").write_text( + "Fix the diffball foobar functionality.\n" + ) + + # Nothing should be in the Manifest yet + with self.assertRaises(KeyError): + manifest.getFileData("AUX", "test.patch", "SHA512") + + manifest.addFile("AUX", "files/test.patch") + + self.assertEqual(len(manifest.fhashdict["AUX"].keys()), 1) + self.assertEqual( + manifest.getFileData("AUX", "test.patch", "SHA512"), + "e30d069dcf284cbcb2d5685f03ca362469026b469dec4f8655d0c9a2bf317f5d9f68f61855ea403f4959bc0b9c003ae824fb9d6ab2472a739950623523af9da9", + )