diff options
author | Josh Smith <qinusty@gmail.com> | 2018-08-29 10:38:53 +0100 |
---|---|---|
committer | Qinusty <jrsmith9822@gmail.com> | 2018-08-29 13:02:04 +0000 |
commit | 582e0c05be81cedb174704e509c87391036c4841 (patch) | |
tree | 322d251ebea7f302c8c55c9b4544e63422bc6c6a | |
parent | 557fb81adca9fbe408c339415ad3ab377bac7a81 (diff) | |
download | buildstream-582e0c05be81cedb174704e509c87391036c4841.tar.gz |
Prevent ValueError on URLs without an alias
Fixes #597
-rw-r--r-- | buildstream/source.py | 21 | ||||
-rw-r--r-- | buildstream/utils.py | 1 |
2 files changed, 13 insertions, 9 deletions
diff --git a/buildstream/source.py b/buildstream/source.py index 18a9c2e61..79d9e014f 100644 --- a/buildstream/source.py +++ b/buildstream/source.py @@ -184,10 +184,7 @@ class SourceFetcher(): Args: url (str): The url used to download. """ - # Not guaranteed to be a valid alias yet. - # Ensuring it's a valid alias currently happens in Project.get_alias_uris - alias, _ = url.split(utils._ALIAS_SEPARATOR, 1) - self.__alias = alias + self.__alias = _extract_alias(url) ############################################################# # Private Methods used in BuildStream # @@ -386,8 +383,7 @@ class Source(Plugin): *Since: 1.2* """ - alias, _ = url.split(utils._ALIAS_SEPARATOR, 1) - self.__expected_alias = alias + self.__expected_alias = _extract_alias(url) def get_source_fetchers(self): """Get the objects that are used for fetching @@ -452,8 +448,7 @@ class Source(Plugin): else: # Sneakily store the alias if it hasn't already been stored if not self.__expected_alias and url and utils._ALIAS_SEPARATOR in url: - url_alias, _ = url.split(utils._ALIAS_SEPARATOR, 1) - self.__expected_alias = url_alias + self.mark_download_url(url) project = self._get_project() return project.translate_url(url, first_pass=self.__first_pass) @@ -804,12 +799,12 @@ class Source(Plugin): # Tries to call track for every mirror, stopping once it succeeds def __do_track(self): project = self._get_project() - # If there are no mirrors, or no aliases to replace, there's nothing to do here. alias = self._get_alias() if self.__first_pass: mirrors = project.first_pass_config.mirrors else: mirrors = project.config.mirrors + # If there are no mirrors, or no aliases to replace, there's nothing to do here. if not mirrors or not alias: return self.track() @@ -867,3 +862,11 @@ class Source(Plugin): _yaml.node_final_assertions(config) return config + + +def _extract_alias(url): + parts = url.split(utils._ALIAS_SEPARATOR, 1) + if len(parts) > 1 and not parts[0].lower() in utils._URI_SCHEMES: + return parts[0] + else: + return "" diff --git a/buildstream/utils.py b/buildstream/utils.py index eecc820f2..efecdc2e5 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -44,6 +44,7 @@ from ._exceptions import BstError, ErrorDomain # The separator we use for user specified aliases _ALIAS_SEPARATOR = ':' +_URI_SCHEMES = ["http", "https", "ftp", "file", "git", "sftp", "ssh"] class UtilError(BstError): |