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.
pull/6966/head
Xavier Claessens 5 years ago committed by Jussi Pakkanen
parent 6ebf674798
commit a6239d5100
  1. 2
      docs/markdown/Wrap-dependency-system-manual.md
  2. 4
      docs/markdown/snippets/wrap_fallback.md
  3. 25
      mesonbuild/wrap/wrap.py
  4. 6
      run_unittests.py

@ -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

@ -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.

@ -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:

@ -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))

Loading…
Cancel
Save