Blame SOURCES/BZ-1369389-dont-recommend-makecache-if-running.patch

5e9bef
commit 79591f49db4faec56a846ddf16a77004b8579ee7
5e9bef
Author: Michal Domonkos <mdomonko@redhat.com>
5e9bef
Date:   Thu Dec 15 16:23:10 2016 +0100
5e9bef
5e9bef
    Don't recommend makecache if just running. BZ 1369389
5e9bef
    
5e9bef
    Also includes any other commands that would result in all repos obeying
5e9bef
    metadata_expire such as "yum install" (depending on the actual value of
5e9bef
    metadata_expire_filter).
5e9bef
5e9bef
diff --git a/cli.py b/cli.py
5e9bef
index 54a2e81..862992b 100755
5e9bef
--- a/cli.py
5e9bef
+++ b/cli.py
5e9bef
@@ -450,11 +450,21 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
5e9bef
 
5e9bef
         if not ts_min:
5e9bef
             cacheReq = 'write'
5e9bef
-        elif warning and (time.time() - ts_max) > (60 * 60 * 24 * 14):
5e9bef
-            self.logger.warning(_("Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast"))
5e9bef
 
5e9bef
+        all_obey = True
5e9bef
         for repo in self.repos.sort():
5e9bef
             repo._metadata_cache_req = cacheReq
5e9bef
+            if repo._matchExpireFilter():
5e9bef
+                all_obey = False
5e9bef
+
5e9bef
+        if warning and ts_min and (time.time() - ts_max) > (60 * 60 * 24 * 14):
5e9bef
+            # The warning makes no sense if we're already running a command
5e9bef
+            # that requires current repodata across all repos (such as "yum
5e9bef
+            # makecache" or others, depending on metadata_expire_filter), so
5e9bef
+            # don't give it if that's the case.
5e9bef
+            if all_obey:
5e9bef
+                return
5e9bef
+            self.logger.warning(_("Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast"))
5e9bef
 
5e9bef
     def _shell_history_write(self):
5e9bef
         if not hasattr(self, '_shell_history_cmds'):
5e9bef
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
5e9bef
index c6bed82..0c63de3 100644
5e9bef
--- a/yum/yumRepo.py
5e9bef
+++ b/yum/yumRepo.py
5e9bef
@@ -1145,33 +1145,39 @@ Insufficient space in download directory %s
5e9bef
             self._metadataCurrent = False
5e9bef
         return self._metadataCurrent
5e9bef
 
5e9bef
-    def withinCacheAge(self, myfile, expiration_time, expire_req_filter=True):
5e9bef
-        """check if any file is older than a certain amount of time. Used for
5e9bef
-           the cachecookie and the mirrorlist
5e9bef
-           return True if w/i the expiration time limit
5e9bef
-           false if the time limit has expired
5e9bef
-
5e9bef
-           Additionally compare the file to age of the newest .repo or yum.conf
5e9bef
-           file. If any of them are newer then invalidate the cache
5e9bef
-           """
5e9bef
-
5e9bef
+    def _matchExpireFilter(self):
5e9bef
+        """Return whether cache_req matches metadata_expire_filter."""
5e9bef
         # Never/write means we just skip this...
5e9bef
-        if (expire_req_filter and hasattr(self, '_metadata_cache_req') and
5e9bef
-            self._metadata_cache_req.startswith("read-only:") and
5e9bef
-            self.metadata_expire_filter.startswith("read-only:")):
5e9bef
+        if (hasattr(self, '_metadata_cache_req') and
5e9bef
+                self._metadata_cache_req.startswith("read-only:") and
5e9bef
+                self.metadata_expire_filter.startswith("read-only:")):
5e9bef
 
5e9bef
             cache_filt = self.metadata_expire_filter[len("read-only:"):]
5e9bef
             cache_req  = self._metadata_cache_req[len("read-only:"):]
5e9bef
 
5e9bef
             if cache_filt == 'future':
5e9bef
                 assert cache_req in ('past', 'present', 'future')
5e9bef
-                expiration_time = -1
5e9bef
+                return True
5e9bef
             if cache_filt == 'present':
5e9bef
                 if cache_req in ('past', 'present'):
5e9bef
-                    expiration_time = -1
5e9bef
+                    return True
5e9bef
             if cache_filt == 'past':
5e9bef
                 if cache_req == 'past':
5e9bef
-                    expiration_time = -1
5e9bef
+                    return True
5e9bef
+        return False
5e9bef
+
5e9bef
+    def withinCacheAge(self, myfile, expiration_time, expire_req_filter=True):
5e9bef
+        """check if any file is older than a certain amount of time. Used for
5e9bef
+           the cachecookie and the mirrorlist
5e9bef
+           return True if w/i the expiration time limit
5e9bef
+           false if the time limit has expired
5e9bef
+
5e9bef
+           Additionally compare the file to age of the newest .repo or yum.conf
5e9bef
+           file. If any of them are newer then invalidate the cache
5e9bef
+           """
5e9bef
+
5e9bef
+        if expire_req_filter and self._matchExpireFilter():
5e9bef
+            expiration_time = -1
5e9bef
 
5e9bef
         # -1 is special and should never get refreshed
5e9bef
         if expiration_time == -1 and os.path.exists(myfile):