summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-17 17:08:39 +0900
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2018-04-17 08:31:48 +0000
commit4fc2da9ad0ac077db7b675db272d901d2249f66f (patch)
treefc7bd7cb15dc9522615b6bb36dd69a4e786f4804
parent548c03f58b878fe685933e6e4d8209e80d37b8f5 (diff)
downloadbuildstream-4fc2da9ad0ac077db7b675db272d901d2249f66f.tar.gz
element.py: Fix force opening of workspaces.
This was broken because we let the Source objects initialize workspaces directly in the target workspace directory, where files might already exist. Instead, initialize the workspace in a tempdir and hardlink the files from there. This fixes issue #364
-rw-r--r--buildstream/element.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index 324efa86c..398df6655 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1676,11 +1676,26 @@ class Element(Plugin):
# the workspaces metadata first.
#
def _open_workspace(self):
+ context = self._get_context()
workspace = self._get_workspace()
assert workspace is not None
- for source in self.sources():
- source._init_workspace(workspace.path)
+ # First lets get a temp dir in our build directory
+ # and stage there, then link the files over to the desired
+ # path.
+ #
+ # We do this so that force opening workspaces which overwrites
+ # files in the target directory actually works without any
+ # additional support from Source implementations.
+ #
+ os.makedirs(context.builddir, exist_ok=True)
+ with utils._tempdir(dir=context.builddir, prefix='workspace-{}'
+ .format(self.normal_name)) as temp:
+ for source in self.sources():
+ source._init_workspace(temp)
+
+ # Now hardlink the files into the workspace target.
+ utils.link_files(temp, workspace.path)
# _get_workspace():
#