From 8f66e5e3a8ae35f46224497583f6d0c473d4b74e Mon Sep 17 00:00:00 2001 From: Otto Urpelainen Date: Oct 12 2021 16:53:40 +0000 Subject: [PATCH 1/2] Consider Patch tags in specfile parser Patch files can be uploaded to the lookaside cache and referred to by Patch tags in the specfile. The specfile parser did not consider this case, leading to an error if a dist-git repo has such confiration. Fixed by parsing the patch tags. Resolves RHBZ#2010518 Signed-off-by: Otto Urpelainen --- diff --git a/pyrpkg/spec.py b/pyrpkg/spec.py index a276120..bd862f1 100644 --- a/pyrpkg/spec.py +++ b/pyrpkg/spec.py @@ -14,8 +14,9 @@ from pyrpkg.errors import rpkgError class SpecFile(object): """Simple specfile parser that finds source file names""" - - sourcefile_expression = re.compile(r'^source[0-9]*:\s*(?P.*)\s*$', re.IGNORECASE) + sourcefile_expression = re.compile( + r'^((source[0-9]*|patch[0-9]*):\s*(?P.*))\s*$', + re.IGNORECASE) def __init__(self, spec, sourcedir): self.spec = spec diff --git a/tests/test_spec.py b/tests/test_spec.py index 196b470..eefc475 100644 --- a/tests/test_spec.py +++ b/tests/test_spec.py @@ -36,8 +36,11 @@ class SpecFileTestCase(unittest.TestCase): spec_fd.write( "Source0: https://example.com/tarball.tar.gz\n" "Source1: https://example.com/subdir/LICENSE.txt\n" - "Source2: https://another.domain.com/source.tar.gz\n" - "Source3: local.txt\n") + "source2: https://another.domain.com/source.tar.gz\n" + "SOURCE3: local.txt\n" + "\n" + "patch0: local.patch\n" + "PAtch999: https://remote.patch-sourcce.org/another-patch.bz2\n") spec_fd.close() s = spec.SpecFile(self.specfile, self.workdir) @@ -46,7 +49,9 @@ class SpecFileTestCase(unittest.TestCase): "tarball.tar.gz", "LICENSE.txt", "source.tar.gz", - "local.txt"] + "local.txt", + "local.patch", + "another-patch.bz2"] self.assertEqual(len(actual), len(expected)) self.assertTrue(all([a == b for a, b in zip(actual, expected)])) From 7b653abc28bdff3401df94ac89106b5eb56658cc Mon Sep 17 00:00:00 2001 From: Otto Urpelainen Date: Oct 12 2021 18:05:44 +0000 Subject: [PATCH 2/2] Continue execution if specfile parsing fails The unused sources detection feature implemented by class SpecFile is simply an optimization to avoid downloading unused sources. The parsing is quite different from other steps performed by rpkg, which also meant it can fail in new ways. To avoid situations where an error in this optimization step prevents usage that would otherwise succeed, this commit changes handling of such errors from exiting to logging the situation and continuing with the assumption that all sources in the sources file may be needed. Resolves #583 Signed-off-by: Otto Urpelainen --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 23bca5b..ee289e0 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -2042,8 +2042,15 @@ class Commands(object): outdir = self.path sourcesf = SourcesFile(self.sources_filename, self.source_entry_type) - specf = SpecFile(os.path.join(self.layout.specdir, self.spec), - self.layout.sourcedir) + + try: + specf = SpecFile(os.path.join(self.layout.specdir, self.spec), + self.layout.sourcedir) + spec_parsed = True + except Exception as err: + self.log.warn("Parsing specfile for used sources failed. " + "Falling back to downloading all sources.") + spec_parsed = False args = dict() if self.lookaside_request_params: @@ -2062,7 +2069,7 @@ class Commands(object): "Error: Attempting a download '{0}' that would override a git tracked file. " "Either remove the corresponding line from 'sources' file to keep the git " "tracked one or 'git rm' the file to allow the download.".format(outfile)) - if (entry.file not in specf.sources): + if (spec_parsed and entry.file not in specf.sources): self.log.info("Not downloading unused %s" % entry.file) continue self.lookasidecache.download(