tar to a temp path and atomically rename if successful, else delete
Signed-off-by: Rachel Kroll <rkroll@google.com>
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3161 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/packages.py b/client/common_lib/packages.py
index ed99c78..b7872ad 100644
--- a/client/common_lib/packages.py
+++ b/client/common_lib/packages.py
@@ -716,9 +716,16 @@
the source. Returns the tarball path.
'''
tarball_path = os.path.join(dest_dir, pkg_name)
- cmd = "tar -cvjf %s -C %s %s " % (tarball_path, src_dir, exclude_string)
+ temp_path = tarball_path + '.tmp'
+ cmd = "tar -cvjf %s -C %s %s " % (temp_path, src_dir, exclude_string)
- utils.system(cmd)
+ try:
+ utils.system(cmd)
+ except:
+ os.unlink(temp_path)
+ raise
+
+ os.rename(temp_path, tarball_path)
return tarball_path