[Notes] [Git][BuildStream/buildstream][bst-1.2] 2 commits: Prevent ValueError on URLs without an alias



Title: GitLab

Qinusty pushed to branch bst-1.2 at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/source.py
    ... ... @@ -184,10 +184,7 @@ class SourceFetcher():
    184 184
             Args:
    
    185 185
                url (str): The url used to download.
    
    186 186
             """
    
    187
    -        # Not guaranteed to be a valid alias yet.
    
    188
    -        # Ensuring it's a valid alias currently happens in Project.get_alias_uris
    
    189
    -        alias, _ = url.split(utils._ALIAS_SEPARATOR, 1)
    
    190
    -        self.__alias = alias
    
    187
    +        self.__alias = _extract_alias(url)
    
    191 188
     
    
    192 189
         #############################################################
    
    193 190
         #            Private Methods used in BuildStream            #
    
    ... ... @@ -386,8 +383,7 @@ class Source(Plugin):
    386 383
     
    
    387 384
             *Since: 1.2*
    
    388 385
             """
    
    389
    -        alias, _ = url.split(utils._ALIAS_SEPARATOR, 1)
    
    390
    -        self.__expected_alias = alias
    
    386
    +        self.__expected_alias = _extract_alias(url)
    
    391 387
     
    
    392 388
         def get_source_fetchers(self):
    
    393 389
             """Get the objects that are used for fetching
    
    ... ... @@ -452,8 +448,7 @@ class Source(Plugin):
    452 448
             else:
    
    453 449
                 # Sneakily store the alias if it hasn't already been stored
    
    454 450
                 if not self.__expected_alias and url and utils._ALIAS_SEPARATOR in url:
    
    455
    -                url_alias, _ = url.split(utils._ALIAS_SEPARATOR, 1)
    
    456
    -                self.__expected_alias = url_alias
    
    451
    +                self.mark_download_url(url)
    
    457 452
     
    
    458 453
                 project = self._get_project()
    
    459 454
                 return project.translate_url(url, first_pass=self.__first_pass)
    
    ... ... @@ -804,12 +799,12 @@ class Source(Plugin):
    804 799
         # Tries to call track for every mirror, stopping once it succeeds
    
    805 800
         def __do_track(self):
    
    806 801
             project = self._get_project()
    
    807
    -        # If there are no mirrors, or no aliases to replace, there's nothing to do here.
    
    808 802
             alias = self._get_alias()
    
    809 803
             if self.__first_pass:
    
    810 804
                 mirrors = project.first_pass_config.mirrors
    
    811 805
             else:
    
    812 806
                 mirrors = project.config.mirrors
    
    807
    +        # If there are no mirrors, or no aliases to replace, there's nothing to do here.
    
    813 808
             if not mirrors or not alias:
    
    814 809
                 return self.track()
    
    815 810
     
    
    ... ... @@ -867,3 +862,11 @@ class Source(Plugin):
    867 862
             _yaml.node_final_assertions(config)
    
    868 863
     
    
    869 864
             return config
    
    865
    +
    
    866
    +
    
    867
    +def _extract_alias(url):
    
    868
    +    parts = url.split(utils._ALIAS_SEPARATOR, 1)
    
    869
    +    if len(parts) > 1 and not parts[0].lower() in utils._URI_SCHEMES:
    
    870
    +        return parts[0]
    
    871
    +    else:
    
    872
    +        return ""

  • buildstream/utils.py
    ... ... @@ -44,6 +44,7 @@ from ._exceptions import BstError, ErrorDomain
    44 44
     
    
    45 45
     # The separator we use for user specified aliases
    
    46 46
     _ALIAS_SEPARATOR = ':'
    
    47
    +_URI_SCHEMES = ["http", "https", "ftp", "file", "git", "sftp", "ssh"]
    
    47 48
     
    
    48 49
     
    
    49 50
     class UtilError(BstError):
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]