diff options
author | Chandan Singh <csingh43@bloomberg.net> | 2018-02-17 22:43:14 +0000 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2018-02-19 17:00:40 +0100 |
commit | 3937f24c500887973db58ca4934adbdbd2f2a82e (patch) | |
tree | b32322a09ab6e1f31e59bcf308e814df8425f634 | |
parent | a10ef1a4db25b408841c4b20cec64315cb085b59 (diff) | |
download | buildstream-3937f24c500887973db58ca4934adbdbd2f2a82e.tar.gz |
Create workspace directory after checking for potential issues
At present, in case that `bst workspace open` for reasons such as
sources not being tracked or if tracking fails, BuildStream will leave
behind an empty directort corresponding to the workspace. Restructure
code so that workspace directory is only created after other checks
have passed.
Fixes #200.
-rw-r--r-- | buildstream/_pipeline.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index 47caf28c3..7328d7d38 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -563,15 +563,6 @@ class Pipeline(): if len(list(target.sources())) == 0: raise PipelineError("The given element has no sources") - # Check directory - try: - os.makedirs(directory, exist_ok=True) - except OSError as e: - raise PipelineError("Failed to create workspace directory: {}".format(e)) from e - - if not no_checkout and not force and os.listdir(directory): - raise PipelineError("Checkout directory is not empty: {}".format(directory)) - # Check for workspace config if self.project._get_workspace(target.name): raise PipelineError("Workspace '{}' is already defined." @@ -608,14 +599,24 @@ class Pipeline(): self.message(MessageType.SUCCESS, "Fetched {} elements".format(fetched), elapsed=elapsed) + if not no_checkout and target._consistency() != Consistency.CACHED: + raise PipelineError("Could not stage uncached source. " + + "Use `--track` to track and " + + "fetch the latest version of the " + + "source.") + + # Check directory + try: + os.makedirs(directory, exist_ok=True) + except OSError as e: + raise PipelineError("Failed to create workspace directory: {}".format(e)) from e + if not no_checkout: + if not force and os.listdir(directory): + raise PipelineError("Checkout directory is not empty: {}".format(directory)) + with target.timed_activity("Staging sources to {}".format(directory)): for source in target.sources(): - if source.get_consistency() != Consistency.CACHED: - raise PipelineError("Could not stage uncached source. " + - "Use `--track` to track and " + - "fetch the latest version of the " + - "source.") source._init_workspace(directory) self.project._set_workspace(target, workdir) |