ud-generate: Also rebuild if one of our keyrings has changed, even if ldap has not.
authorPeter Palfrader <peter@palfrader.org>
Wed, 11 Apr 2012 08:55:50 +0000 (10:55 +0200)
committerPeter Palfrader <peter@palfrader.org>
Wed, 11 Apr 2012 08:55:50 +0000 (10:55 +0200)
debian/changelog
ud-generate

index 30fafbc..b8327dd 100644 (file)
@@ -51,6 +51,8 @@ userdir-ldap (0.3.80) UNRELEASED; urgency=low
     the rsync call in an flock wrapper that acquires a shared lock on
     ud-generate's lock.  This prevents syncing while ud-generate runs.
   * ud-lock: support supplying a status to set instead of 'retiring'.
+  * ud-generate: Also rebuild if one of our keyrings has changed, even if
+    ldap has not.
 
   [ Stephen Gran ]
   * Fix deprecation warnings for sha module by using hashlib module instead
@@ -66,7 +68,7 @@ userdir-ldap (0.3.80) UNRELEASED; urgency=low
     - add webPasswords
     - add mailPreserveSuffixSeperator
 
- -- Peter Palfrader <weasel@debian.org>  Thu, 29 Mar 2012 23:44:56 +0200
+ -- Peter Palfrader <weasel@debian.org>  Wed, 11 Apr 2012 10:55:17 +0200
 
 userdir-ldap (0.3.79) unstable; urgency=low
 
index 51437b2..0f6b5ae 100755 (executable)
@@ -1251,15 +1251,26 @@ def getLastLDAPChangeTime(l):
 
    return last
 
+def getLastKeyringChangeTime():
+   krmod = 0
+   for k in Keyrings:
+      mt = os.path.getmtime(k)
+      if mt > krmod:
+         krmod = mt
+
+   return krmod
+
 def getLastBuildTime(gdir):
-   cache_last_mod = 0
+   cache_last_ldap_mod = 0
+   cache_last_unix_mod = 0
 
    try:
       fd = open(os.path.join(gdir, "last_update.trace"), "r")
       cache_last_mod=fd.read().split()
       try:
-         cache_last_mod = cache_last_mod[0]
-      except IndexError:
+         cache_last_ldap_mod = cache_last_mod[0]
+         cache_last_unix_mod = int(cache_last_mod[1])
+      except IndexError, ValueError:
          pass
       fd.close()
    except IOError, e:
@@ -1268,8 +1279,7 @@ def getLastBuildTime(gdir):
       else:
          raise e
 
-   return cache_last_mod
-
+   return (cache_last_ldap_mod, cache_last_unix_mod)
 
 def ud_generate():
    parser = optparse.OptionParser()
@@ -1299,19 +1309,22 @@ def ud_generate():
 
    l = make_ldap_conn()
 
+   time_started = int(time.time())
    ldap_last_mod = getLastLDAPChangeTime(l)
-   cache_last_mod = getLastBuildTime(generate_dir)
-   need_update = ldap_last_mod > cache_last_mod
+   unix_last_mod = getLastKeyringChangeTime()
+   cache_last_ldap_mod, cache_last_unix_mod = getLastBuildTime(generate_dir)
+
+   need_update = (ldap_last_mod > cache_last_ldap_mod) or (unix_last_mod > cache_last_unix_mod)
 
    if not options.force and not need_update:
       fd = open(os.path.join(generate_dir, "last_update.trace"), "w")
-      fd.write("%s\n%s\n" % (ldap_last_mod, int(time.time())))
+      fd.write("%s\n%s\n" % (ldap_last_mod, time_started))
       fd.close()
       sys.exit(0)
 
    tracefd = open(os.path.join(generate_dir, "last_update.trace"), "w")
    generate_all(generate_dir, l)
-   tracefd.write("%s\n%s\n" % (ldap_last_mod, int(time.time())))
+   tracefd.write("%s\n%s\n" % (ldap_last_mod, time_started))
    tracefd.close()