summaryrefslogtreecommitdiff
path: root/buildstream/_cas
diff options
context:
space:
mode:
authorValentin David <valentin.david@codethink.co.uk>2019-02-11 18:51:20 +0100
committerValentin David <valentin.david@gmail.com>2019-02-12 18:06:50 +0000
commit478e5c47ac96bbe165c4f2908f48754d4495804c (patch)
tree7e45f077b10db4e825b3aa021991d519895ff670 /buildstream/_cas
parente51116d5763edd98b9d7397c14c0e83dd432a8f3 (diff)
downloadbuildstream-478e5c47ac96bbe165c4f2908f48754d4495804c.tar.gz
buildstream/_cas/cascache.py: Set 0644 rights to pulled filesvalentindavid/pull-chmod-bug
This was broken by 5ef19a0b31df84caed1e41719ef7ea5c6bd8a8bc.
Diffstat (limited to 'buildstream/_cas')
-rw-r--r--buildstream/_cas/cascache.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/buildstream/_cas/cascache.py b/buildstream/_cas/cascache.py
index 9d7a121f4..560587055 100644
--- a/buildstream/_cas/cascache.py
+++ b/buildstream/_cas/cascache.py
@@ -376,9 +376,7 @@ class CASCache():
for chunk in iter(lambda: tmp.read(_BUFFER_SIZE), b""):
h.update(chunk)
else:
- 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)
+ tmp = stack.enter_context(self._temporary_object())
if path:
with open(path, 'rb') as f:
@@ -827,6 +825,19 @@ class CASCache():
for dirnode in directory.directories:
yield from self._required_blobs(dirnode.digest)
+ # _temporary_object():
+ #
+ # Returns:
+ # (file): A file object to a named temporary file.
+ #
+ # Create a named temporary file with 0o0644 access rights.
+ @contextlib.contextmanager
+ def _temporary_object(self):
+ with utils._tempnamedfile(dir=self.tmpdir) as f:
+ os.chmod(f.name,
+ stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
+ yield f
+
# _ensure_blob():
#
# Fetch and add blob if it's not already local.
@@ -844,7 +855,7 @@ class CASCache():
# already in local repository
return objpath
- with utils._tempnamedfile(dir=self.tmpdir) as f:
+ with self._temporary_object() as f:
remote._fetch_blob(digest, f)
added_digest = self.add_object(path=f.name, link_directly=True)
@@ -854,7 +865,7 @@ class CASCache():
def _batch_download_complete(self, batch):
for digest, data in batch.send():
- with utils._tempnamedfile(dir=self.tmpdir) as f:
+ with self._temporary_object() as f:
f.write(data)
f.flush()