summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>2019-02-25 16:41:56 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-03-13 17:40:57 +0000
commit874e932dc04686266d2230adf95b0eaba0f6a065 (patch)
treebc25d1373768eebc59ffa2fb7195def7a11ea44f
parent27b500d033cc6d2b7b2d23b27f3294a5c580d422 (diff)
downloadbuildstream-874e932dc04686266d2230adf95b0eaba0f6a065.tar.gz
utils: add deterministic_umask context manager
Useful for when exporting file from cas. Part of #870
-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)