yifengyou / rpms / yum

Forked from rpms/yum 3 years ago
Clone

Blame SOURCES/BZ-1194915-add-logging-for-bad-notice-dupes.patch

5e9bef
diff -up yum-3.4.3/yum/update_md.py.org yum-3.4.3/yum/update_md.py
5e9bef
--- yum-3.4.3/yum/update_md.py.org	2017-01-24 18:55:03.529842775 +0100
5e9bef
+++ yum-3.4.3/yum/update_md.py	2017-01-24 18:55:57.213511475 +0100
5e9bef
@@ -58,7 +58,7 @@ class UpdateNotice(object):
5e9bef
     A single update notice (for instance, a security fix).
5e9bef
     """
5e9bef
 
5e9bef
-    def __init__(self, elem=None):
5e9bef
+    def __init__(self, elem=None, repoid=None, vlogger=None):
5e9bef
         self._md = {
5e9bef
             'from'             : '',
5e9bef
             'type'             : '',
5e9bef
@@ -83,6 +83,9 @@ class UpdateNotice(object):
5e9bef
         if elem:
5e9bef
             self._parse(elem)
5e9bef
 
5e9bef
+        self._repoid = repoid
5e9bef
+        self._vlogger = vlogger
5e9bef
+
5e9bef
     def __getitem__(self, item):
5e9bef
         """ Allows scriptable metadata access (ie: un['update_id']). """
5e9bef
         if type(item) is int:
5e9bef
@@ -103,6 +106,24 @@ class UpdateNotice(object):
5e9bef
         #  Tests to see if it's "the same data", which means that the
5e9bef
         # packages can be different (see add_notice).
5e9bef
 
5e9bef
+        def _rid(un):
5e9bef
+            if hasattr(un, '_repoid') and un._repoid is not None:
5e9bef
+                return un._repoid
5e9bef
+            else:
5e9bef
+                return '<unknown>'
5e9bef
+
5e9bef
+        def _log_failure(data):
5e9bef
+            """Log the mismatched data similarly to conflict markers in git."""
5e9bef
+            if self._vlogger is None:
5e9bef
+                return
5e9bef
+            msg = _('Duplicate of %s differs in some fields:\n')
5e9bef
+            msg %= other._md['update_id']
5e9bef
+            msg += '<<<<<<< %s:%s\n' % (_rid(other), data)
5e9bef
+            msg += '%r\n=======\n%r\n' % (other._md[data], self._md[data])
5e9bef
+            msg += '>>>>>>> %s:%s' % (_rid(self), data)
5e9bef
+            # --verbose mode enables this
5e9bef
+            self._vlogger.log(logginglevels.DEBUG_3, msg)
5e9bef
+
5e9bef
         if not other or not hasattr(other, '_md'):
5e9bef
             return False
5e9bef
 
5e9bef
@@ -113,6 +134,7 @@ class UpdateNotice(object):
5e9bef
             if data == 'status': # FIXME: See below...
5e9bef
                 continue
5e9bef
             if self._md[data] != other._md[data]:
5e9bef
+                _log_failure(data)
5e9bef
                 return False
5e9bef
         # FIXME: Massive hack, Fedora is really broken and gives status=stable
5e9bef
         # and status=testing for updateinfo notices, just depending on which
5e9bef
@@ -120,8 +142,10 @@ class UpdateNotice(object):
5e9bef
         data = 'status'
5e9bef
         if self._md[data] != other._md[data]:
5e9bef
             if self._md[data]  not in ('stable', 'testing'):
5e9bef
+                _log_failure(data)
5e9bef
                 return False
5e9bef
             if other._md[data] not in ('stable', 'testing'):
5e9bef
+                _log_failure(data)
5e9bef
                 return False
5e9bef
             # They are both really "stable" ...
5e9bef
             self._md[data]  = 'stable'
5e9bef
@@ -574,7 +598,7 @@ class UpdateMetadata(object):
5e9bef
         for event, elem in safe_iterparse(infile, logger=self._logger):
5e9bef
             if elem.tag == 'update':
5e9bef
                 try:
5e9bef
-                    un = UpdateNotice(elem)
5e9bef
+                    un = UpdateNotice(elem, repoid, self._vlogger)
5e9bef
                 except UpdateNoticeException, e:
5e9bef
                     msg = _("An update notice%s is broken, skipping.") % _rid(repoid)
5e9bef
                     if self._vlogger:
5e9bef
@@ -587,6 +611,8 @@ class UpdateMetadata(object):
5e9bef
                     msg = _("Update notice %s%s is broken, or a bad duplicate, skipping.") % (un['update_id'], _rid(repoid))
5e9bef
                     if not have_dup:
5e9bef
                         msg += _('\nYou should report this problem to the owner of the %srepository.') % _rid(repoid, "%s ")
5e9bef
+                        msg += _('\nIf you are the owner, consider re-running the same command with --verbose to see the '
5e9bef
+                                 'exact data that caused the conflict.')
5e9bef
                     have_dup = True
5e9bef
                     if self._vlogger:
5e9bef
                         self._vlogger.warn("%s", msg)