Skip to content

Commit

Permalink
cosalib/build: Use workdir tmp/ as tempdir
Browse files Browse the repository at this point in the history
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: coreos/fedora-coreos-tracker#361
  • Loading branch information
jlebon committed Feb 4, 2020
1 parent 44d3094 commit 19dae9d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/cosalib/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 19dae9d

Please sign in to comment.