fbeaedc
From 7ede78fc7b8fae2e78c700f39eb68df1696e107f Mon Sep 17 00:00:00 2001
fbeaedc
From: Otto Urpelainen <oturpe@iki.fi>
fbeaedc
Date: Tue, 12 Oct 2021 20:48:43 +0300
fbeaedc
Subject: [PATCH] Continue execution if specfile parsing fails
fbeaedc
fbeaedc
The unused sources detection feature implemented by class SpecFile
fbeaedc
is simply an optimization to avoid downloading unused sources.
fbeaedc
The parsing is quite different from other steps performed by rpkg,
fbeaedc
which also meant it can fail in new ways.
fbeaedc
To avoid situations where an error in this optimization step prevents
fbeaedc
usage that would otherwise succeed, this commit changes handling
fbeaedc
of such errors from exiting to logging the situation and continuing
fbeaedc
with the assumption that all sources in the sources file may
fbeaedc
be needed.
fbeaedc
fbeaedc
Resolves: #583
fbeaedc
JIRA: RHELCMP-7087
fbeaedc
Merges: https://pagure.io/rpkg/pull-request/581
fbeaedc
fbeaedc
Signed-off-by: Otto Urpelainen <oturpe@iki.fi>
fbeaedc
---
fbeaedc
 pyrpkg/__init__.py | 13 ++++++++++---
fbeaedc
 1 file changed, 10 insertions(+), 3 deletions(-)
fbeaedc
fbeaedc
diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
fbeaedc
index 23bca5b..2edcb09 100644
fbeaedc
--- a/pyrpkg/__init__.py
fbeaedc
+++ b/pyrpkg/__init__.py
fbeaedc
@@ -2042,8 +2042,15 @@ class Commands(object):
fbeaedc
             outdir = self.path
fbeaedc
 
fbeaedc
         sourcesf = SourcesFile(self.sources_filename, self.source_entry_type)
fbeaedc
-        specf = SpecFile(os.path.join(self.layout.specdir, self.spec),
fbeaedc
-                         self.layout.sourcedir)
fbeaedc
+
fbeaedc
+        try:
fbeaedc
+            specf = SpecFile(os.path.join(self.layout.specdir, self.spec),
fbeaedc
+                             self.layout.sourcedir)
fbeaedc
+            spec_parsed = True
fbeaedc
+        except Exception:
fbeaedc
+            self.log.warn("Parsing specfile for used sources failed. "
fbeaedc
+                          "Falling back to downloading all sources.")
fbeaedc
+            spec_parsed = False
fbeaedc
 
fbeaedc
         args = dict()
fbeaedc
         if self.lookaside_request_params:
fbeaedc
@@ -2062,7 +2069,7 @@ class Commands(object):
fbeaedc
                     "Error: Attempting a download '{0}' that would override a git tracked file. "
fbeaedc
                     "Either remove the corresponding line from 'sources' file to keep the git "
fbeaedc
                     "tracked one or 'git rm' the file to allow the download.".format(outfile))
fbeaedc
-            if (entry.file not in specf.sources):
fbeaedc
+            if (spec_parsed and entry.file not in specf.sources):
fbeaedc
                 self.log.info("Not downloading unused %s" % entry.file)
fbeaedc
                 continue
fbeaedc
             self.lookasidecache.download(
fbeaedc
-- 
fbeaedc
2.31.1
fbeaedc