Blob Blame History Raw
From bb12945220cc99e8797bb1ced74cdc0e7efb4df0 Mon Sep 17 00:00:00 2001
From: Otto Urpelainen <oturpe@iki.fi>
Date: Tue, 5 Oct 2021 08:50:28 +0300
Subject: [PATCH] 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 <oturpe@iki.fi>
---
 pyrpkg/spec.py     |  5 +++--
 tests/test_spec.py | 11 ++++++++---
 2 files changed, 11 insertions(+), 5 deletions(-)

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<val>.*)\s*$', re.IGNORECASE)
+    sourcefile_expression = re.compile(
+        r'^((source[0-9]*|patch[0-9]*):\s*(?P<val>.*))\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)]))
 
-- 
2.31.1