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

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