summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-02-27 18:40:21 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-02-28 00:07:10 +0900
commitce6ea0e1ae6b95a5d623c4b4aa0c777e4b4eb98c (patch)
treedf226166f381a64c7f894f0b822d6aac11c2a5f5
parent9e3a26aadb844a98f3b91b494e333f6984bed5b5 (diff)
downloadbuildstream-ce6ea0e1ae6b95a5d623c4b4aa0c777e4b4eb98c.tar.gz
sandbox/_mount.py: Ensure file existence for bind mounts
This logic existed but is now a bit more complex with the addition of allowing explicit bind mounts to be defined for the shell; the change is that now files can also be mounted into the sandbox instead of just directories.
-rw-r--r--buildstream/sandbox/_mount.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/buildstream/sandbox/_mount.py b/buildstream/sandbox/_mount.py
index a4f82575e..062082f3b 100644
--- a/buildstream/sandbox/_mount.py
+++ b/buildstream/sandbox/_mount.py
@@ -54,12 +54,28 @@ class Mount():
self.mount_source = os.path.join(self.mount_base, 'mount')
self.mount_tempdir = os.path.join(self.mount_base, 'temp')
os.makedirs(self.mount_origin, exist_ok=True)
- os.makedirs(self.mount_source, exist_ok=True)
os.makedirs(self.mount_tempdir, exist_ok=True)
else:
# No redirection needed
self.mount_source = os.path.join(root_directory, mount_point.lstrip(os.sep))
+
+ external_mount_sources = sandbox._get_mount_sources()
+ external_mount_source = external_mount_sources.get(mount_point)
+
+ if external_mount_source is None:
os.makedirs(self.mount_source, exist_ok=True)
+ else:
+ if os.path.isdir(external_mount_source):
+ os.makedirs(self.mount_source, exist_ok=True)
+ else:
+ # When mounting a regular file, ensure the parent
+ # directory exists in the sandbox; and that an empty
+ # file is created at the mount location.
+ parent_dir = os.path.dirname(self.mount_source.rstrip('/'))
+ os.makedirs(parent_dir, exist_ok=True)
+ if not os.path.exists(self.mount_source):
+ with open(self.mount_source, 'w'):
+ pass
@contextmanager
def mounted(self, sandbox):