commit: bd0b901ff3024fbb2289b370bde475b4b435294c Author: Sam James <sam <AT> gentoo <DOT> org> AuthorDate: Fri Oct 7 19:14:28 2022 +0000 Commit: Sam James <sam <AT> gentoo <DOT> 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 <sam <AT> 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", + )
