Blame SOURCES/BZ-1065380-updateinfo-strip-respin.patch

eb5f31
commit 7b92efd65fea5187d295ffc4fcb49dcfbe822623
eb5f31
Author: Michal Domonkos <mdomonko@redhat.com>
eb5f31
Date:   Tue May 17 13:04:52 2016 +0200
eb5f31
eb5f31
    updateinfo: strip respin suffix if present. BZ 1065380
eb5f31
eb5f31
diff --git a/docs/yum.8 b/docs/yum.8
eb5f31
index 9c09c48..efaa061 100644
eb5f31
--- a/docs/yum.8
eb5f31
+++ b/docs/yum.8
eb5f31
@@ -1091,6 +1091,17 @@ To get the information on advisory FEDORA-2707-4567 use:
eb5f31
 .IP
eb5f31
 yum updateinfo info FEDORA-2707-4567
eb5f31
 .PP
eb5f31
+For Red Hat advisories, respin suffixes are also accepted in the ID, although
eb5f31
+they won't have any effect on the actual respin selected by yum, as it will
eb5f31
+always select the latest one available.  For example, if you use:
eb5f31
+.IP
eb5f31
+yum updateinfo info RHSA-2016:1234-2
eb5f31
+.PP
eb5f31
+while RHSA-2016:1234-3 has been shipped already, yum will select the latter
eb5f31
+(provided your updateinfo.xml is current).  The same would happen if you just
eb5f31
+specified RHSA-2016:1234.  That said, there's no need for you to specify or
eb5f31
+care about the suffix at all.
eb5f31
+.PP
eb5f31
 To update packages to the latest version which contain fixes for Bugzillas 123, 456 and 789; and all security updates use:
eb5f31
 .IP
eb5f31
 yum --bz 123 --bz 456 --bz 789 --security update
eb5f31
diff --git a/yum/updateinfo.py b/yum/updateinfo.py
eb5f31
index 2b39330..7abe332 100644
eb5f31
--- a/yum/updateinfo.py
eb5f31
+++ b/yum/updateinfo.py
eb5f31
@@ -1,5 +1,6 @@
eb5f31
 
eb5f31
 import os.path
eb5f31
+import re
eb5f31
 
eb5f31
 from yum.i18n import _, P_
eb5f31
 
eb5f31
@@ -172,6 +173,40 @@ def _args2filters(args):
eb5f31
             filters[T] = filters.get(T, []) + arg1.split(',')
eb5f31
         return filters
eb5f31
 
eb5f31
+def _ysp_gen_opts(filters, sec_cmds=None):
eb5f31
+    def strip_respin(id_):
eb5f31
+        # Example: RHSA-2016:1234-2 -> RHSA-2016:1234
eb5f31
+        pattern = r'^(RH[BES]A\-\d+\:\d+)(\-\d+)?$'
eb5f31
+        match = re.match(pattern, id_)
eb5f31
+        if match:
eb5f31
+            return match.group(1)
eb5f31
+        return id_
eb5f31
+
eb5f31
+    opts = _updateinfofilter2opts(filters)
eb5f31
+    if sec_cmds is not None:
eb5f31
+        opts.sec_cmds = sec_cmds
eb5f31
+
eb5f31
+    # If a RH advisory was specified with a respin suffix, strip it out, as we
eb5f31
+    # don't include these suffixes in the notice update_id attribute either (we
eb5f31
+    # use the version attribute for that).  Note that there's no ambiguity in
eb5f31
+    # which notice version we should match then, as updateinfo.xml should only
eb5f31
+    # contain one per advisory ID (we give a warning when duplicate IDs are
eb5f31
+    # detected in it).  The reason we are handling this is that we sometimes
eb5f31
+    # refer to advisories in this form (e.g. on rhn.redhat.com/errata/...) and
eb5f31
+    # the user may then use it with yum too, in which case we would yield no
eb5f31
+    # matches.
eb5f31
+    #
eb5f31
+    # However, we used to put these suffixes in update_id in the past, so let's
eb5f31
+    # also keep the original (unstripped) form around in opts, just in case we
eb5f31
+    # are dealing with such an old updateinfo.xml.
eb5f31
+    for attr in ['sec_cmds', 'advisory']:
eb5f31
+        oldlist = getattr(opts, attr)
eb5f31
+        stripped = map(strip_respin, oldlist)
eb5f31
+        newlist = list(set(oldlist) | set(stripped))
eb5f31
+        setattr(opts, attr, newlist)
eb5f31
+
eb5f31
+    return opts
eb5f31
+
eb5f31
 def _ysp_gen_used_map(opts):
eb5f31
     used_map = {'bugzilla' : {}, 'cve' : {}, 'id' : {}, 'cmd' : {}, 'sev' : {}}
eb5f31
     if True:
eb5f31
@@ -308,7 +343,7 @@ def remove_txmbrs(base, filters=None):
eb5f31
 
eb5f31
     if filters is None:
eb5f31
         filters = base.updateinfo_filters
eb5f31
-    opts = _updateinfofilter2opts(filters)
eb5f31
+    opts = _ysp_gen_opts(filters)
eb5f31
 
eb5f31
     if _no_options(opts):
eb5f31
         return 0, 0, 0
eb5f31
@@ -392,7 +427,7 @@ def exclude_updates(base, filters=None):
eb5f31
 
eb5f31
     if filters is None:
eb5f31
         filters = base.updateinfo_filters
eb5f31
-    opts = _updateinfofilter2opts(filters)
eb5f31
+    opts = _ysp_gen_opts(filters)
eb5f31
 
eb5f31
     if _no_options(opts):
eb5f31
         return 0, 0
eb5f31
@@ -446,7 +481,7 @@ def exclude_all(base, filters=None):
eb5f31
 
eb5f31
     if filters is None:
eb5f31
         filters = base.updateinfo_filters
eb5f31
-    opts = _updateinfofilter2opts(filters)
eb5f31
+    opts = _ysp_gen_opts(filters)
eb5f31
 
eb5f31
     if _no_options(opts):
eb5f31
         return 0, 0
eb5f31
@@ -487,7 +522,7 @@ def update_minimal(base, extcmds=[]):
eb5f31
     txmbrs = []
eb5f31
 
eb5f31
     used_map = _ysp_gen_used_map(base.updateinfo_filters)
eb5f31
-    opts     = _updateinfofilter2opts(base.updateinfo_filters)
eb5f31
+    opts     = _ysp_gen_opts(base.updateinfo_filters)
eb5f31
     ndata    = _no_options(opts)
eb5f31
 
eb5f31
     # NOTE: Not doing obsoletes processing atm. ... maybe we should? --
eb5f31
--- yum-3.4.3/yumcommands.py.orig	2016-05-19 12:58:38.354630030 +0200
eb5f31
+++ yum-3.4.3/yumcommands.py	2016-05-19 12:59:37.385260152 +0200
eb5f31
@@ -4071,7 +4071,6 @@
eb5f31
             # or -q deletes everything.
eb5f31
             print x
eb5f31
 
eb5f31
-        opts = _upi._updateinfofilter2opts(base.updateinfo_filters)
eb5f31
         extcmds, show_type, filt_type = self._parse_extcmds(extcmds)
eb5f31
 
eb5f31
         list_type = "available"
eb5f31
@@ -4081,7 +4080,7 @@
eb5f31
             if filt_type is None:
eb5f31
                 extcmds, show_type, filt_type = self._parse_extcmds(extcmds)
eb5f31
 
eb5f31
-        opts.sec_cmds = extcmds
eb5f31
+        opts = _upi._ysp_gen_opts(base.updateinfo_filters, extcmds)
eb5f31
         used_map = _upi._ysp_gen_used_map(base.updateinfo_filters)
eb5f31
         iname2tup = {}
eb5f31
         if False: pass