[Piuparts-commits] [piuparts] 03/20: p-s: improve create_or_replace_chroot_tgz

Holger Levsen holger at moszumanska.debian.org
Sat Nov 23 20:23:34 UTC 2013


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to branch develop
in repository piuparts.

commit 141b4c262c1a7f5c6a31f389c4ad60005bc5a30e
Author: Andreas Beckmann <anbe at debian.org>
Date:   Sat Nov 9 17:07:02 2013 +0100

    p-s: improve create_or_replace_chroot_tgz
    
    Signed-off-by: Andreas Beckmann <anbe at debian.org>
---
 piuparts-slave.py | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/piuparts-slave.py b/piuparts-slave.py
index 37c6b3d..bd75a83 100644
--- a/piuparts-slave.py
+++ b/piuparts-slave.py
@@ -858,28 +858,21 @@ def create_chroot(config, tarball, distro):
 def create_or_replace_chroot_tgz(config, tgz, distro):
     max_tgz_age = int(config["max-tgz-age"])
     min_tgz_retry_delay = int(config["min-tgz-retry-delay"])
-    forced = 0
-    if os.path.exists(tgz) and max_tgz_age > 0:
+    needs_update = not os.path.exists(tgz)
+    if not needs_update and max_tgz_age > 0:
+        # tgz exists and age is limited, so check age
         now = time.time()
-        statobj = os.stat(tgz)
-        # stat.ST_MTIME is actually time file was initially created
-        age = now - statobj[stat.ST_MTIME]
+        age = now - os.path.getmtime(tgz)
         logging.info("Check-replace %s: age=%d vs. max=%d" % (tgz, age, max_tgz_age))
         if age > max_tgz_age:
-            logging.info("Limit-replace %s: last-retry=%d vs. min=%d" % (tgz, now - statobj[stat.ST_CTIME], min_tgz_retry_delay))
-            # stat.ST_CTIME is time created OR last renamed
-            if min_tgz_retry_delay is None or now - statobj[stat.ST_CTIME] > min_tgz_retry_delay:
-                os.rename(tgz, tgz + ".old")
-                forced = 1
-                logging.info("%s too old.  Renaming to force re-creation" % tgz)
-    if not os.path.exists(tgz):
+            if os.path.exists(tgz + ".log"):
+                age = now - os.path.getmtime(tgz + ".log")
+            logging.info("Limit-replace %s: last-retry=%d vs. min=%d" % (tgz, age, min_tgz_retry_delay))
+            if age > min_tgz_retry_delay:
+                needs_update = True
+                logging.info("%s too old.  Forcing re-creation" % tgz)
+    if needs_update:
         create_chroot(config, tgz, distro)
-        if forced:
-            if not os.path.exists(tgz):
-                os.rename(tgz + ".old", tgz)
-                logging.info("Failed to create ... reverting to old %s" % tgz)
-            else:
-                os.unlink(tgz + ".old")
 
 
 def create_file(filename, contents):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/piuparts/piuparts.git



More information about the Piuparts-commits mailing list