diff options
-rw-r--r-- | buildstream/_artifactcache/cascache.py | 2 | ||||
-rw-r--r-- | buildstream/utils.py | 10 |
2 files changed, 8 insertions, 4 deletions
diff --git a/buildstream/_artifactcache/cascache.py b/buildstream/_artifactcache/cascache.py index 14932fba2..ffeccc0b3 100644 --- a/buildstream/_artifactcache/cascache.py +++ b/buildstream/_artifactcache/cascache.py @@ -418,7 +418,7 @@ class CASCache(ArtifactCache): def set_ref(self, ref, tree): refpath = self._refpath(ref) os.makedirs(os.path.dirname(refpath), exist_ok=True) - with utils.save_file_atomic(refpath, 'wb') as f: + with utils.save_file_atomic(refpath, 'wb', tempdir=self.tmpdir) as f: f.write(tree.SerializeToString()) # resolve_ref(): diff --git a/buildstream/utils.py b/buildstream/utils.py index efecdc2e5..34c0f898b 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -496,7 +496,7 @@ def get_bst_version(): @contextmanager def save_file_atomic(filename, mode='w', *, buffering=-1, encoding=None, - errors=None, newline=None, closefd=True, opener=None): + errors=None, newline=None, closefd=True, opener=None, tempdir=None): """Save a file with a temporary name and rename it into place when ready. This is a context manager which is meant for saving data to files. @@ -523,8 +523,9 @@ def save_file_atomic(filename, mode='w', *, buffering=-1, encoding=None, # https://bugs.python.org/issue8604 assert os.path.isabs(filename), "The utils.save_file_atomic() parameter ``filename`` must be an absolute path" - dirname = os.path.dirname(filename) - fd, tempname = tempfile.mkstemp(dir=dirname) + if tempdir is None: + tempdir = os.path.dirname(filename) + fd, tempname = tempfile.mkstemp(dir=tempdir) os.close(fd) f = open(tempname, mode=mode, buffering=buffering, encoding=encoding, @@ -556,6 +557,9 @@ def save_file_atomic(filename, mode='w', *, buffering=-1, encoding=None, # # Get the disk usage of a given directory in bytes. # +# This function assumes that files do not inadvertantly +# disappear while this function is running. +# # Arguments: # (str) The path whose size to check. # |