summaryrefslogtreecommitdiff
path: root/buildstream
diff options
context:
space:
mode:
authorRaoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>2019-02-25 16:41:56 +0000
committerJürg Billeter <j@bitron.ch>2019-03-14 07:12:34 +0000
commit1109b800dafc41d9e4428ca9e1b40542de671f9c (patch)
tree170fbdee0853372367b5a443208d10442a9f9bc6 /buildstream
parentcbc5af53e7dc6b2d450728f6c17b9a79ff167990 (diff)
downloadbuildstream-1109b800dafc41d9e4428ca9e1b40542de671f9c.tar.gz
utils: add deterministic_umask context manager
Useful for when exporting file from cas. Part of #870
Diffstat (limited to 'buildstream')
-rw-r--r--buildstream/element.py3
-rw-r--r--buildstream/utils.py15
2 files changed, 17 insertions, 1 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index b9643aee9..a77f7e6dc 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1491,7 +1491,8 @@ class Element(Plugin):
for source in self.sources():
source._stage(import_dir)
- vdirectory.import_files(import_dir)
+ with utils._deterministic_umask():
+ vdirectory.import_files(import_dir)
# Ensure deterministic mtime of sources at build time
vdirectory.set_deterministic_mtime()
diff --git a/buildstream/utils.py b/buildstream/utils.py
index 2960348e9..f4a329210 100644
--- a/buildstream/utils.py
+++ b/buildstream/utils.py
@@ -1307,3 +1307,18 @@ def _with_gc_disabled(func):
# used by other objects during the course of running BuildStream.
gc.collect()
return _gc_disabled
+
+
+# _deterministic_umask()
+#
+# Context managed to apply a umask to a section that may be affected by a users
+# umask. Restores old mask afterwards.
+#
+@contextmanager
+def _deterministic_umask():
+ old_umask = os.umask(0o022)
+
+ try:
+ yield
+ finally:
+ os.umask(old_umask)