Blame SOURCES/BZ-1337105-add-lazy-packages-caching-opt.patch

d2a170
diff -up yum-3.4.3/docs/yum.conf.5.orig yum-3.4.3/docs/yum.conf.5
d2a170
--- yum-3.4.3/docs/yum.conf.5.orig	2016-08-02 15:08:10.160947580 +0200
d2a170
+++ yum-3.4.3/docs/yum.conf.5	2016-08-02 15:08:30.046853379 +0200
d2a170
@@ -381,6 +381,13 @@ that Yum does. This option can take the
d2a170
 `packages' means that only RPM package downloads should be cached (but not
d2a170
 repository metadata downloads).
d2a170
 
d2a170
+`lazy:packages' means that act like `packages' unless package verification
d2a170
+fails (e.g. the package download doesn't match the expected checksum), in which
d2a170
+case try re-downloading the package as if `none' was set.  This value is a good
d2a170
+compromise if you want to avoid issues caused by stale proxy cache after remote
d2a170
+RPMs change contents without changing filenames (e.g. are pushed unsigned and
d2a170
+later signed) but still want the benefits of package caching whenever possible.
d2a170
+
d2a170
 `none' means that no HTTP downloads should be cached.
d2a170
 
d2a170
 The default is `all'. This is recommended unless you are experiencing caching
d2a170
diff -up yum-3.4.3/output.py.orig yum-3.4.3/output.py
d2a170
--- yum-3.4.3/output.py.orig	2016-08-02 15:08:10.074947988 +0200
d2a170
+++ yum-3.4.3/output.py	2016-08-02 15:08:30.053853346 +0200
d2a170
@@ -472,6 +472,13 @@ class YumOutput:
d2a170
         :raises: *errobj*.exception
d2a170
         """
d2a170
         self.logger.error('%s: %s', errobj.url, errobj.exception)
d2a170
+        if hasattr(errobj, 'retry_no_cache') and errobj.retry_no_cache and \
d2a170
+                errobj.exception.errno < 0:
d2a170
+            self.logger.error(_('Trying again, now avoiding proxy cache.'))
d2a170
+            # Raising an exception would cause urlgrabber to jump to the next
d2a170
+            # mirror and what we want here is to retry with the same, so just
d2a170
+            # return.
d2a170
+            return
d2a170
         self.logger.error(_('Trying other mirror.'))
d2a170
         self.suggestKBaseArticle(errobj)
d2a170
         raise errobj.exception
d2a170
diff -up yum-3.4.3/yum/config.py.orig yum-3.4.3/yum/config.py
d2a170
--- yum-3.4.3/yum/config.py.orig	2016-08-02 15:08:10.159947585 +0200
d2a170
+++ yum-3.4.3/yum/config.py	2016-08-02 15:08:30.048853370 +0200
d2a170
@@ -810,7 +810,8 @@ class YumConf(StartupConf):
d2a170
     deltarpm_percentage = IntOption(75, range_min=0, range_max=100)
d2a170
     deltarpm_metadata_percentage = IntOption(100, range_min=0)
d2a170
 
d2a170
-    http_caching = SelectionOption('all', ('none', 'packages', 'all'))
d2a170
+    http_caching = SelectionOption('all', ('none', 'packages', 'all',
d2a170
+                                           'lazy:packages'))
d2a170
     metadata_expire = SecondsOption(60 * 60 * 6) # Time in seconds (6h).
d2a170
     metadata_expire_filter = SelectionOption('read-only:present',
d2a170
                                              ('never', 'read-only:future',
d2a170
diff -up yum-3.4.3/yum/__init__.py.orig yum-3.4.3/yum/__init__.py
d2a170
diff -up yum-3.4.3/yum.spec.orig yum-3.4.3/yum.spec
d2a170
--- yum-3.4.3/yum.spec.orig	2016-08-02 15:08:10.150947628 +0200
d2a170
+++ yum-3.4.3/yum.spec	2016-08-02 15:08:30.047853374 +0200
d2a170
@@ -63,7 +63,7 @@ BuildRequires: python >= 2.4
d2a170
 BuildRequires: rpm-python, rpm >= 0:4.4.2
d2a170
 BuildRequires: python-iniparse
d2a170
 BuildRequires: python-sqlite
d2a170
-BuildRequires: python-urlgrabber >= 3.9.0-8
d2a170
+BuildRequires: python-urlgrabber >= 3.10-8
d2a170
 BuildRequires: yum-metadata-parser >= 1.1.0
d2a170
 BuildRequires: pygpgme
d2a170
 # End of CheckRequires
d2a170
@@ -72,7 +72,7 @@ Requires: python >= 2.4
d2a170
 Requires: rpm-python, rpm >= 0:4.4.2
d2a170
 Requires: python-iniparse
d2a170
 Requires: python-sqlite
d2a170
-Requires: python-urlgrabber >= 3.9.0-8
d2a170
+Requires: python-urlgrabber >= 3.10-8
d2a170
 Requires: yum-metadata-parser >= 1.1.0
d2a170
 Requires: pygpgme
d2a170
 # rawhide is >= 0.5.3-7.fc18 ... as this is added.
d2a170
diff -up yum-3.4.3/yum/yumRepo.py.orig yum-3.4.3/yum/yumRepo.py
d2a170
--- yum-3.4.3/yum/yumRepo.py.orig	2016-08-02 15:08:10.104947846 +0200
d2a170
+++ yum-3.4.3/yum/yumRepo.py	2016-08-02 15:08:30.052853351 +0200
d2a170
@@ -336,6 +336,7 @@ class YumRepository(Repository, config.R
d2a170
         self._repoXML = None
d2a170
         self._oldRepoMDData = {}
d2a170
         self.cache = 0
d2a170
+        self._retry_no_cache = False
d2a170
         self.mirrorlistparsed = 0
d2a170
         self.yumvar = {} # empty dict of yumvariables for $string replacement
d2a170
         self._proxy_dict = {}
d2a170
@@ -993,6 +994,7 @@ Insufficient space in download directory
d2a170
                             interrupt_callback=self.interrupt_callback,
d2a170
                             checkfunc=checkfunc,
d2a170
                             size=size,
d2a170
+                            retry_no_cache=self._retry_no_cache,
d2a170
                             **ugopts)
d2a170
 
d2a170
             remote = url + '/' + relative
d2a170
@@ -1020,6 +1022,7 @@ Insufficient space in download directory
d2a170
                                            checkfunc=checkfunc,
d2a170
                                            http_headers=headers,
d2a170
                                            size=size,
d2a170
+                                           retry_no_cache=self._retry_no_cache,
d2a170
                                            **kwargs
d2a170
                                            )
d2a170
             except URLGrabError, e:
d2a170
@@ -1049,15 +1052,22 @@ Insufficient space in download directory
d2a170
                     misc.unlink_f(local)
d2a170
                     raise URLGrabError(-1, _('Package does not match intended download.'))
d2a170
 
d2a170
-        ret = self._getFile(url=basepath,
d2a170
-                        relative=remote,
d2a170
-                        local=local,
d2a170
-                        checkfunc=checkfunc,
d2a170
-                        text=text,
d2a170
-                        cache=cache,
d2a170
-                        size=package.size,
d2a170
-                        **kwargs
d2a170
-                        )
d2a170
+        # We would normally pass this to _getFile() directly but that could
d2a170
+        # break backward compatibility with plugins that override _getFile()
d2a170
+        # (BZ 1360532).
d2a170
+        self._retry_no_cache = self.http_caching == 'lazy:packages'
d2a170
+        try:
d2a170
+            ret = self._getFile(url=basepath,
d2a170
+                            relative=remote,
d2a170
+                            local=local,
d2a170
+                            checkfunc=checkfunc,
d2a170
+                            text=text,
d2a170
+                            cache=cache,
d2a170
+                            size=package.size,
d2a170
+                            **kwargs
d2a170
+                            )
d2a170
+        finally:
d2a170
+            self._retry_no_cache = False
d2a170
 
d2a170
         if not kwargs.get('async') and not package.verifyLocalPkg():
d2a170
             # Don't return as "success" when bad.