diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-01-18 14:29:13 -0500 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2019-01-18 14:36:26 -0500 |
commit | 8ce483d431f1be51e1c2051d15c2c47453bab0eb (patch) | |
tree | 6030968e7a99c52e7fa0e8ee9bb4e4e026d3404c | |
parent | 99699ffc1f50805b17cbc44635ce68a2668b7769 (diff) | |
download | buildstream-8ce483d431f1be51e1c2051d15c2c47453bab0eb.tar.gz |
_cas/cascache.py: Use utils._tempdir() and utils._tempnamedfile()
The direct usage of tempfile.TemporaryDirectory() and
tempfile.NamedTemporaryFile() here causes leakage of any temporary
data when the process operating on temporary data is terminated
with SIGTERM.
Using the utilities ensures that trash is not left behind in
~/.cache/buildstream/artifacts/tmp when the user terminates
BuildStream with ^C.
-rw-r--r-- | buildstream/_cas/cascache.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/buildstream/_cas/cascache.py b/buildstream/_cas/cascache.py index 1092f6f75..5a6251815 100644 --- a/buildstream/_cas/cascache.py +++ b/buildstream/_cas/cascache.py @@ -22,7 +22,6 @@ import itertools import os import stat import errno -import tempfile import uuid import contextlib @@ -130,7 +129,7 @@ class CASCache(): else: return dest - with tempfile.TemporaryDirectory(prefix='tmp', dir=self.tmpdir) as tmpdir: + with utils._tempdir(prefix='tmp', dir=self.tmpdir) as tmpdir: checkoutdir = os.path.join(tmpdir, ref) self._checkout(checkoutdir, tree) @@ -375,7 +374,7 @@ class CASCache(): for chunk in iter(lambda: tmp.read(4096), b""): h.update(chunk) else: - tmp = stack.enter_context(tempfile.NamedTemporaryFile(dir=self.tmpdir)) + tmp = stack.enter_context(utils._tempnamedfile(dir=self.tmpdir)) # Set mode bits to 0644 os.chmod(tmp.name, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) @@ -843,7 +842,7 @@ class CASCache(): # already in local repository return objpath - with tempfile.NamedTemporaryFile(dir=self.tmpdir) as f: + with utils._tempnamedfile(dir=self.tmpdir) as f: remote._fetch_blob(digest, f) added_digest = self.add_object(path=f.name, link_directly=True) @@ -853,7 +852,7 @@ class CASCache(): def _batch_download_complete(self, batch): for digest, data in batch.send(): - with tempfile.NamedTemporaryFile(dir=self.tmpdir) as f: + with utils._tempnamedfile(dir=self.tmpdir) as f: f.write(data) f.flush() @@ -950,7 +949,7 @@ class CASCache(): def _fetch_tree(self, remote, digest): # download but do not store the Tree object - with tempfile.NamedTemporaryFile(dir=self.tmpdir) as out: + with utils._tempnamedfile(dir=self.tmpdir) as out: remote._fetch_blob(digest, out) tree = remote_execution_pb2.Tree() |