[Server-devel] [PATCH] xs-publish-xobuild: better tmp statefile, overwrite if needed

Martin Langhoff martin at laptop.org
Mon Aug 11 02:12:55 EDT 2008


After testing a few error scenarios, we need these fixes to
handle them better

 - We now use a real tmp file for the state - truncated state
   files kill fakeroot otherwise, making recovery much harder.

 - When we could overwrite... we overwrite. no more --force
   needed. This makes recovery in unexpected cases much simpler.
   --force is still accepted, but it's a noop for now. We may
   use it later.
---
 xs-publish-xobuild.py |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/xs-publish-xobuild.py b/xs-publish-xobuild.py
index 3d10851..dc7f80a 100755
--- a/xs-publish-xobuild.py
+++ b/xs-publish-xobuild.py
@@ -70,17 +70,20 @@ def main():
     ##
     ## untar under fakeroot
     ##
+    # having the tmpdir in the same partition makes final mv op atomic
+    os.environ['TMPDIR'] = options.tmpdir
+
     destdir = os.path.join(destdir,buildname,'root')
     if os.path.exists(destdir):
-        if options.force:
-            check_call(['rm', '-fr', destdir])
-        else:
-            raise RuntimeError('Destination directory already exists')
-    check_call(['mkdir', '-p', destdir])
-    tmpstatefile = os.path.join(options.statedir, buildname+".tmp")
+        # We'll overwrite it regardless
+        # as some error conditions leave an incomplete
+        # directory in place.
+        check_call(['rm', '-fr', destdir])
 
-    # having the tmpdir in the same partition makes final mv op atomic
-    os.environ['TMPDIR'] = options.tmpdir
+    check_call(['mkdir', '-p', destdir])
+    (tmpfh, tmpfpath) = tempfile.mkstemp()
+    os.close(tmpfh)
+    tmpstatefile = tmpfpath
 
     basepath = os.path.dirname(sys.argv[0])
     check_call(['flock', tmpstatefile,
-- 
1.5.5.1



More information about the Server-devel mailing list