Skip to content
Snippets Groups Projects
Commit cc5f1f94 authored by Tiago Gomes's avatar Tiago Gomes
Browse files

cascache: move tmp directory one level up

The tmp directory is filled when adding an artifact with temporary
files. This causes problems on calculate_cache_size() because we could
try to a attemp to do a stat() on a temporary file that meanwhile has
been reaped.

Handle this by not considering the tmp directory when calculating the
cache size.
parent e42325b9
No related branches found
No related tags found
No related merge requests found
Pipeline #27363700 failed
......@@ -56,7 +56,10 @@ class CASCache(ArtifactCache):
super().__init__(context)
self.casdir = os.path.join(context.artifactdir, 'cas')
os.makedirs(os.path.join(self.casdir, 'tmp'), exist_ok=True)
os.makedirs(self.casdir, exist_ok=True)
self.tmpdir = os.path.join(context.artifactdir, 'tmp')
os.makedirs(self.tmpdir, exist_ok=True)
self._enable_push = enable_push
......@@ -394,7 +397,7 @@ class CASCache(ArtifactCache):
try:
h = hashlib.sha256()
# Always write out new file to avoid corruption if input file is modified
with tempfile.NamedTemporaryFile(dir=os.path.join(self.casdir, 'tmp')) as out:
with tempfile.NamedTemporaryFile(dir=self.tmpdir) as out:
# Set mode bits to 0644
os.chmod(out.name, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
......@@ -764,7 +767,7 @@ class CASCache(ArtifactCache):
# already in local cache
return
with tempfile.NamedTemporaryFile(dir=os.path.join(self.casdir, 'tmp')) as out:
with tempfile.NamedTemporaryFile(dir=self.tmpdir) as out:
self._fetch_blob(remote, tree, out)
directory = remote_execution_pb2.Directory()
......@@ -778,7 +781,7 @@ class CASCache(ArtifactCache):
# already in local cache
continue
with tempfile.NamedTemporaryFile(dir=os.path.join(self.casdir, 'tmp')) as f:
with tempfile.NamedTemporaryFile(dir=self.tmpdir) as f:
self._fetch_blob(remote, filenode.digest, f)
digest = self.add_object(path=f.name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment