summaryrefslogtreecommitdiff
path: root/buildstream
diff options
context:
space:
mode:
authorJim MacArthur <jim.macarthur@codethink.co.uk>2018-08-23 13:30:28 +0100
committerJim MacArthur <jim.macarthur@codethink.co.uk>2018-08-24 10:51:27 +0100
commite1ed09aaed1eb43fb25ffbb7db7cee7bc877ab69 (patch)
treeed59321201d47c41275598b720f24a66a8980922 /buildstream
parent255f9ee3eb512e64ca5a674c1144345e5d79843b (diff)
downloadbuildstream-e1ed09aaed1eb43fb25ffbb7db7cee7bc877ab69.tar.gz
element.py: chmod 777 directories if delete fails.
Staging may produce directories with less than 'rwx' permissions which will cause tempfile to throw an exception on deleting the temporary directory if not changed.
Diffstat (limited to 'buildstream')
-rw-r--r--buildstream/element.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index a34b1ca36..d9c096992 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1361,8 +1361,12 @@ class Element(Plugin):
if not vdirectory.is_empty():
raise ElementError("Staging directory '{}' is not empty".format(vdirectory))
- with tempfile.TemporaryDirectory() as temp_staging_directory:
+ # While mkdtemp is advertised as using the TMP environment variable, it
+ # doesn't, so this explicit extraction is necesasry.
+ tmp_prefix = os.environ.get("TMP", None)
+ temp_staging_directory = tempfile.mkdtemp(prefix=tmp_prefix)
+ try:
workspace = self._get_workspace()
if workspace:
# If mount_workspaces is set and we're doing incremental builds,
@@ -1377,6 +1381,19 @@ class Element(Plugin):
source._stage(temp_staging_directory)
vdirectory.import_files(temp_staging_directory)
+
+ finally:
+ # Staging may produce directories with less than 'rwx' permissions
+ # for the owner, which will break tempfile, so we need to use chmod
+ # occasionally.
+ def make_dir_writable(fn, path, excinfo):
+ os.chmod(os.path.dirname(path), 0o777)
+ if os.path.isdir(path):
+ os.rmdir(path)
+ else:
+ os.remove(path)
+ shutil.rmtree(temp_staging_directory, onerror=make_dir_writable)
+
# Ensure deterministic mtime of sources at build time
vdirectory.set_deterministic_mtime()
# Ensure deterministic owners of sources at build time