[Piuparts-commits] [piuparts] 06/17: p: use a tempfile when creating a tarball
Holger Levsen
holger at alioth.debian.org
Wed Nov 6 09:45:53 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 72b395dc759140b6578eee6956dccf71d689c47a
Author: Andreas Beckmann <anbe at debian.org>
Date: Tue Nov 5 20:05:22 2013 +0100
p: use a tempfile when creating a tarball
and rename this afterwards
to avoid several instances writing to the same file
Signed-off-by: Andreas Beckmann <anbe at debian.org>
---
debian/changelog | 1 +
piuparts.py | 12 +++++++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/debian/changelog b/debian/changelog
index 2b14734..cc8383e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,7 @@ piuparts (0.56) UNRELEASED; urgency=low
* piuparts.py:
- Add to ignored_files:
+ /etc/apt/apt.conf.d/01autoremove-kernels
+ - Use temporary files while creating basetgz and rename afterwards.
* piupartslib/__init__.py:
- open_packages_url(): Try Packages.gz if Packages.bz2 is not available.
(Closes: #711157)
diff --git a/piuparts.py b/piuparts.py
index 84a9d1b..ff99013 100644
--- a/piuparts.py
+++ b/piuparts.py
@@ -872,6 +872,7 @@ class Chroot:
# Yes, create_temp_file() would work just as well, but putting it in
# the interface for Chroot allows the VirtServ hack to work.
(fd, temp_tgz) = create_temp_file()
+ os.close(fd)
return temp_tgz
def remove_temp_tgz_file(self, temp_tgz):
@@ -885,7 +886,16 @@ class Chroot:
self.run(["apt-get", "clean"])
logging.debug("Saving %s to %s." % (self.name, result))
- run(['tar', '-czf', result, '--one-file-system', '--exclude', 'tmp/scripts', '-C', self.name, './'])
+ (fd, tmpfile) = tempfile.mkstemp(dir=os.path.dirname(result))
+ os.close(fd)
+ cleanup_tmpfile = lambda: os.remove(tmpfile)
+ panic_handler_id = do_on_panic(cleanup_tmpfile)
+
+ run(['tar', '-czf', tmpfile, '--one-file-system', '--exclude', 'tmp/scripts', '-C', self.name, './'])
+
+ os.chmod(tmpfile, 0644)
+ os.rename(tmpfile, result)
+ dont_do_on_panic(panic_handler_id)
def unpack_from_tgz(self, tarball):
"""Unpack a tarball to a chroot."""
--
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