Blob Blame History Raw
From 7ede78fc7b8fae2e78c700f39eb68df1696e107f Mon Sep 17 00:00:00 2001
From: Otto Urpelainen <oturpe@iki.fi>
Date: Tue, 12 Oct 2021 20:48:43 +0300
Subject: [PATCH] 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
JIRA: RHELCMP-7087
Merges: https://pagure.io/rpkg/pull-request/581

Signed-off-by: Otto Urpelainen <oturpe@iki.fi>
---
 pyrpkg/__init__.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
index 23bca5b..2edcb09 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:
+            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(
-- 
2.31.1