diff options
-rw-r--r-- | docs/markdown/Wrap-dependency-system-manual.md | 2 | ||||
-rw-r--r-- | docs/markdown/snippets/wrap_fallback.md | 4 | ||||
-rw-r--r-- | mesonbuild/wrap/wrap.py | 25 | ||||
-rwxr-xr-x | run_unittests.py | 6 |
4 files changed, 27 insertions, 10 deletions
diff --git a/docs/markdown/Wrap-dependency-system-manual.md b/docs/markdown/Wrap-dependency-system-manual.md index caad9b0..6e47d58 100644 --- a/docs/markdown/Wrap-dependency-system-manual.md +++ b/docs/markdown/Wrap-dependency-system-manual.md @@ -72,9 +72,11 @@ revision = head ### Specific to wrap-file - `source_url` - download url to retrieve the wrap-file source archive +- `source_fallback_url` - fallback URL to be used when download from `source_url` fails *Since: 0.55.0* - `source_filename` - filename of the downloaded source archive - `source_hash` - sha256 checksum of the downloaded source archive - `patch_url` - download url to retrieve an optional overlay archive +- `patch_fallback_url` - fallback URL to be used when download from `patch_url` fails *Since: 0.55.0* - `patch_filename` - filename of the downloaded overlay archive - `patch_hash` - sha256 checksum of the downloaded overlay archive - `lead_directory_missing` - for `wrap-file` create the leading diff --git a/docs/markdown/snippets/wrap_fallback.md b/docs/markdown/snippets/wrap_fallback.md new file mode 100644 index 0000000..9b71143 --- /dev/null +++ b/docs/markdown/snippets/wrap_fallback.md @@ -0,0 +1,4 @@ +## Wrap fallback URL + +Wrap files can now define `source_fallback_url` and `patch_fallback_url` to be +used in case the main server is temporaly down. 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: diff --git a/run_unittests.py b/run_unittests.py index a9ceddd..4cd6e17 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -6517,11 +6517,13 @@ c = ['{0}'] [wrap-file] directory = foo - source_url = file://{} + source_url = http://server.invalid/foo + source_fallback_url = file://{} source_filename = foo.tar.xz source_hash = {} - patch_url = file://{} + patch_url = http://server.invalid/foo + patch_fallback_url = file://{} patch_filename = foo-patch.tar.xz patch_hash = {} """.format(source_filename, source_hash, patch_filename, patch_hash)) |