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

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