yifengyou / rpms / yum

Forked from rpms/yum 3 years ago
Clone

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

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