summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.com>2017-07-04 11:41:44 +0100
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-04 19:54:21 +0900
commit956a003c018f850151d004f6c123e7e9703f8aaf (patch)
tree95bbd0d787b8ef138cd7c89251b472ca2ca7ffc3
parent448bd5f6843707cbb2e390eac362dc39e88e544c (diff)
downloadbuildstream-956a003c018f850151d004f6c123e7e9703f8aaf.tar.gz
Ensure element permissions are set to euid and egid after staging
-rw-r--r--buildstream/element.py2
-rw-r--r--buildstream/utils.py20
2 files changed, 22 insertions, 0 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index 6e51da9d9..67626d0aa 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1013,6 +1013,8 @@ class Element(Plugin):
# Ensure deterministic mtime of sources at build time
utils._set_deterministic_mtime(directory)
+ # Ensure deterministic owners of sources at build time
+ utils._set_deterministic_user(directory)
#############################################################
# Private Local Methods #
diff --git a/buildstream/utils.py b/buildstream/utils.py
index 7a254fbc2..dad4d5932 100644
--- a/buildstream/utils.py
+++ b/buildstream/utils.py
@@ -605,6 +605,26 @@ def _generate_key(value):
return hashlib.sha256(string).hexdigest()
+# _set_deterministic_user()
+#
+# Set the uid/gid for every file in a directory tree to the process'
+# euid/guid.
+#
+# Args:
+# directory (str): The directory to recursively set the uid/gid on
+#
+def _set_deterministic_user(directory):
+ user = os.geteuid()
+ group = os.getegid()
+
+ for root, dirs, files in os.walk(directory.encode("utf-8"), topdown=False):
+ for filename in files:
+ shutil.chown(os.path.join(root, filename), user, group)
+
+ for dirname in dirs:
+ shutil.chown(os.path.join(root, dirname), user, group)
+
+
# _set_deterministic_mtime()
#
# Set the mtime for every file in a directory tree to the same.