diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2020-04-10 10:10:10 -0400 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2020-04-13 13:29:33 +0300 |
commit | a6239d5100eff74e9358bbd51029bd2810d19f54 (patch) | |
tree | 934837ec92e8bba2f32e38e446d865134f704e90 /mesonbuild/wrap/wrap.py | |
parent | 6ebf674798cb0822ff2242c7cb8ee7abb0b0f6cc (diff) | |
download | meson-a6239d5100eff74e9358bbd51029bd2810d19f54.zip meson-a6239d5100eff74e9358bbd51029bd2810d19f54.tar.gz meson-a6239d5100eff74e9358bbd51029bd2810d19f54.tar.bz2 |
wrap: Add fallback urls
It can happen that a server is temporaly down, tarballs often have
many mirrors available so we should be able to add at least one fallback
mirror in wrap files.
Diffstat (limited to 'mesonbuild/wrap/wrap.py')
-rw-r--r-- | mesonbuild/wrap/wrap.py | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py index 51ad86e..1715cd3 100644 --- a/mesonbuild/wrap/wrap.py +++ b/mesonbuild/wrap/wrap.py @@ -331,7 +331,8 @@ class Resolver: else: try: resp = urllib.request.urlopen(urlstring, timeout=REQ_TIMEOUT) - except urllib.error.URLError: + except urllib.error.URLError as e: + mlog.log(str(e)) raise WrapException('could not get {} is the internet available?'.format(urlstring)) with contextlib.closing(resp) as resp: try: @@ -371,15 +372,23 @@ class Resolver: if dhash != expected: raise WrapException('Incorrect hash for {}:\n {} expected\n {} actual.'.format(what, expected, dhash)) - def download(self, what: str, ofname: str) -> None: + def download(self, what: str, ofname: str, fallback=False) -> None: self.check_can_download() - srcurl = self.wrap.get(what + '_url') + srcurl = self.wrap.get(what + ('_fallback_url' if fallback else '_url')) mlog.log('Downloading', mlog.bold(self.packagename), what, 'from', mlog.bold(srcurl)) - dhash, tmpfile = self.get_data(srcurl) - expected = self.wrap.get(what + '_hash') - if dhash != expected: - os.remove(tmpfile) - raise WrapException('Incorrect hash for {}:\n {} expected\n {} actual.'.format(what, expected, dhash)) + try: + dhash, tmpfile = self.get_data(srcurl) + expected = self.wrap.get(what + '_hash') + if dhash != expected: + os.remove(tmpfile) + raise WrapException('Incorrect hash for {}:\n {} expected\n {} actual.'.format(what, expected, dhash)) + except WrapException: + if not fallback: + if what + '_fallback_url' in self.wrap.values: + return self.download(what, ofname, fallback=True) + mlog.log('A fallback URL could be specified using', + mlog.bold(what + '_fallback_url'), 'key in the wrap file') + raise os.rename(tmpfile, ofname) def get_file_internal(self, what: str) -> str: |