Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 0de537bfd1b4ced04f1f27c3abdc7be2 > files > 5

yum-updatesd-0.9-5.sl5.src.rpm

diff --git a/yum-updatesd b/yum-updatesd
index 5faa6a5..69da1c1 100755
--- a/yum-updatesd
+++ b/yum-updatesd
@@ -28,6 +28,7 @@ import string
 import syslog
 import string
 import subprocess
+import time # For updaterefresh
 
 from optparse import OptionParser
 
@@ -39,6 +40,11 @@ import gobject
 import gamin
 
 from yum.config import BaseConfig, Option, IntOption, ListOption, BoolOption
+try:
+    from yum.config import SecondsOption
+except:
+    class SecondsOption(IntOption):
+        pass
 from yum.parser import ConfigPreProcessor
 from ConfigParser import ConfigParser, ParsingError
 
@@ -51,7 +57,7 @@ NM_ONLINE = 3
 
 class UDConfig(BaseConfig):
     """Config format for the daemon"""
-    run_interval = IntOption(3600)
+    run_interval = SecondsOption(60 * 60) # 1h
     nonroot_workdir = Option("/var/tmp/yum-updatesd")
     emit_via = ListOption(['dbus', 'email', 'syslog'])
     email_to = ListOption(["root"])
@@ -62,7 +68,7 @@ class UDConfig(BaseConfig):
     do_update = BoolOption(False)
     do_download = BoolOption(False)
     do_download_deps = BoolOption(False)
-    updaterefresh = IntOption(3600)
+    updaterefresh = SecondsOption(60 * 60) # 1h
     syslog_facility = Option("DAEMON")
     syslog_level = Option("WARN")
     syslog_ident = Option("yum-updatesd")
@@ -95,7 +101,7 @@ class YumDbusListener(dbus.service.Object):
         self.yumdconfig = config
 
     def doCheck(self):
-        checkUpdates(self.yumdconfig)
+        checkUpdates(self.yumdconfig, limited=True)
         return False
 
     @dbus.service.method("edu.duke.linux.yum", in_signature="")
@@ -136,12 +142,21 @@ def checkHelperStatus():
         return False
     return True
 
-def checkUpdates(opts, wait = False):
+lastUpdate = None
+def checkUpdates(opts, wait = False, limited=False):
+    """ Run yum-updatesd-helper to check for updates and report. Possibly
+        wait for the result, and/or limit the number of updates we try. """
+    global lastUpdate
     global helperProcess
     if helperProcess is not None:
         print >> sys.stderr, "Helper process already running"
         return True
 
+    now = time.time()
+    if limited and lastUpdate and (now - lastUpdate) < opts.updaterefresh:
+        print >> sys.stderr, "Update requested too quickly"
+        return True
+
     if os.path.exists("./yum-updatesd-helper") and opts.debug:
         args = ["./yum-updatesd-helper", "--check"]
     else:
@@ -182,6 +197,7 @@ def checkUpdates(opts, wait = False):
         args.append("--debug")
         print >> sys.stderr, "Going to exec: %s" %(args,)
 
+    lastUpdate = now
     helperProcess = subprocess.Popen(args, close_fds = True)
 
     if not wait:
@@ -234,7 +250,7 @@ def setup_watcher():
 
 def network_state_change(newstate, opts):
     if int(newstate) == NM_ONLINE:
-        checkUpdates(opts)
+        checkUpdates(opts, limited=True)
 
 def main(options = None):
     if options is None:
@@ -288,6 +304,11 @@ def main(options = None):
         pass
     
     run_interval_ms = opts.run_interval * 1000 # needs to be in ms
+    # Note that we don't use limited=True here because:
+    # 1. We could get out of sync. with yum metadata_expire, causing the yum
+    #    UI to hit the network.
+    # 2. If updatesrefresh == run_interval (the default), we could skip every
+    #    other timeout.
     gobject.timeout_add(run_interval_ms, checkUpdates, opts)
 
     # set up file watcher when we're idle
diff --git a/yum-updatesd-helper b/yum-updatesd-helper
index 888d8c2..2a7c451 100755
--- a/yum-updatesd-helper
+++ b/yum-updatesd-helper
@@ -369,6 +369,11 @@ class UpdatesDaemon(yum.YumBase):
                 # gettext.textdomain() and assuming it's from the default
                 # domain for this app)
                 self.emitSetupFailed(str(e))
+        # Override the metadata expire, because there's no point running 
+        # yum-updatesd-helper if we use cached metadata
+        for repo in self.repos.listEnabled():
+            repo.metadata_expire = 1
+
 
     def doLock(self):
         try: