From 74d923a8d9b0eb68b3791de7b161a76c894af83d Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 3 Feb 2020 15:40:02 -0500 Subject: [PATCH] cosalib/build: Use workdir tmp/ as tempdir We changed this behaviour during the refactor. There's quite a bit of history here on why do this. But a major one at least is that we want to be able to just `rename(2)` the final build artifacts into place. This saves a bunch of time and I/O. I noticed this due to the fact that we were losing sparsity from the output of `qemu-img convert` because `shutil.move` doesn't do the equivalent of `cp --sparse=auto`. This patch fixes that, though I think we should also be able to change that call to a simple `os.rename()` in a follow-up to make it explicit. Related: https://github.com/coreos/fedora-coreos-tracker/issues/361 --- src/cosalib/build.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cosalib/build.py b/src/cosalib/build.py index 86c7afc6c8..54595faffb 100644 --- a/src/cosalib/build.py +++ b/src/cosalib/build.py @@ -96,7 +96,12 @@ def __init__(self, *args, **kwargs): self._found_files = {} self._workdir = kwargs.pop("workdir", os.getcwd()) - self._tmpdir = tempfile.mkdtemp(prefix="build_tmpd") + tmpdir = os.path.join(self._workdir, "tmp") + os.environ['TMPDIR'] = tmpdir + + # we need to make sure we allocate in tmp/ so we're on the same + # filesystem as builds/ and we can just `rename()` it there + self._tmpdir = tempfile.mkdtemp(dir=tmpdir) self._image_name = None # Setup the instance properties. @@ -108,7 +113,6 @@ def __init__(self, *args, **kwargs): } os.environ['workdir'] = self._workdir - os.environ['TMPDIR'] = os.path.join(self._workdir, "tmp") # Setup what is required for this Class. # require_cosa means that the COSA information is need