[Notes] [Git][BuildStream/buildstream][Qinusty/597-non-alias-url-fix] Prevent ValueError on URLs without an alias



Title: GitLab

Qinusty pushed to branch Qinusty/597-non-alias-url-fix at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/source.py
    ... ... @@ -219,10 +219,7 @@ class SourceFetcher():
    219 219
             Args:
    
    220 220
                url (str): The url used to download.
    
    221 221
             """
    
    222
    -        # Not guaranteed to be a valid alias yet.
    
    223
    -        # Ensuring it's a valid alias currently happens in Project.get_alias_uris
    
    224
    -        alias, _ = url.split(utils._ALIAS_SEPARATOR, 1)
    
    225
    -        self.__alias = alias
    
    222
    +        self.__alias = _extract_alias(url)
    
    226 223
     
    
    227 224
         #############################################################
    
    228 225
         #            Private Methods used in BuildStream            #
    
    ... ... @@ -459,8 +456,7 @@ class Source(Plugin):
    459 456
     
    
    460 457
             *Since: 1.2*
    
    461 458
             """
    
    462
    -        alias, _ = url.split(utils._ALIAS_SEPARATOR, 1)
    
    463
    -        self.__expected_alias = alias
    
    459
    +        self.__expected_alias = _extract_alias(url)
    
    464 460
     
    
    465 461
         def get_source_fetchers(self):
    
    466 462
             """Get the objects that are used for fetching
    
    ... ... @@ -525,8 +521,7 @@ class Source(Plugin):
    525 521
             else:
    
    526 522
                 # Sneakily store the alias if it hasn't already been stored
    
    527 523
                 if not self.__expected_alias and url and utils._ALIAS_SEPARATOR in url:
    
    528
    -                url_alias, _ = url.split(utils._ALIAS_SEPARATOR, 1)
    
    529
    -                self.__expected_alias = url_alias
    
    524
    +                self.mark_download_url(url)
    
    530 525
     
    
    531 526
                 project = self._get_project()
    
    532 527
                 return project.translate_url(url, first_pass=self.__first_pass)
    
    ... ... @@ -914,12 +909,12 @@ class Source(Plugin):
    914 909
         # Tries to call track for every mirror, stopping once it succeeds
    
    915 910
         def __do_track(self, **kwargs):
    
    916 911
             project = self._get_project()
    
    917
    -        # If there are no mirrors, or no aliases to replace, there's nothing to do here.
    
    918 912
             alias = self._get_alias()
    
    919 913
             if self.__first_pass:
    
    920 914
                 mirrors = project.first_pass_config.mirrors
    
    921 915
             else:
    
    922 916
                 mirrors = project.config.mirrors
    
    917
    +        # If there are no mirrors, or no aliases to replace, there's nothing to do here.
    
    923 918
             if not mirrors or not alias:
    
    924 919
                 return self.track(**kwargs)
    
    925 920
     
    
    ... ... @@ -988,3 +983,11 @@ class Source(Plugin):
    988 983
     
    
    989 984
                 if src.get_consistency() == Consistency.RESOLVED:
    
    990 985
                     src._fetch(previous_sources[0:index])
    
    986
    +
    
    987
    +
    
    988
    +def _extract_alias(url):
    
    989
    +    parts = url.split(utils._ALIAS_SEPARATOR, 1)
    
    990
    +    if len(parts) > 1 and not parts[0].lower() in utils._URI_SCHEMES:
    
    991
    +        return parts[0]
    
    992
    +    else:
    
    993
    +        return ""

  • buildstream/utils.py
    ... ... @@ -47,6 +47,7 @@ _magic_timestamp = calendar.timegm([2011, 11, 11, 11, 11, 11])
    47 47
     
    
    48 48
     # The separator we use for user specified aliases
    
    49 49
     _ALIAS_SEPARATOR = ':'
    
    50
    +_URI_SCHEMES = ["http", "https", "ftp", "file", "git", "sftp", "ssh"]
    
    50 51
     
    
    51 52
     
    
    52 53
     class UtilError(BstError):
    



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