Repository navigation
Do not automatically try downloading from a .gz URL from known broken servers.
#41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,14 +177,36 @@ def info(tools) -> None: | |
| then fallback to "U". This is enabled by default, unless the | ||
| provided URL already points to a compressed file.""", | ||
| ) | ||
| def download(url, output, reference, cache_info, max_retry, try_gzip) -> None: | ||
| @click.option( | ||
| "--broken-hosts-file", | ||
| default="config/broken-hosts.txt", | ||
| type=click.Path(path_type=Path, dir_okay=False), | ||
| help="""A file containing a list of known broken HTTP hosts, from | ||
| which downloading a gzipped file shall not be attempted | ||
| despite --try-gzip.""", | ||
| ) | ||
| def download( | ||
| url, output, reference, cache_info, max_retry, try_gzip, broken_hosts_file | ||
| ) -> None: | ||
| """Download a file.""" | ||
|
|
||
| urlpath = Path(urlparse(url).path) | ||
| urlobj = urlparse(url) | ||
| urlpath = Path(urlobj.path) | ||
| compression = Compression.from_extension(urlpath) | ||
|
|
||
| broken_hosts: List[str] = [] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If try:
with tmpfile.open("wb") as fd:
for chunk in _ResponseWrapper.maybe_wrap(response, comp).iter_content(512):
h.update(chunk)
fd.write(chunk)
except (OSError, EOFError) as e:
tmpfile.unlink(missing_ok=True)
raise DownloadError(f"Cannot decompress file from {response.url}: {e}")(
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That’s a good idea, thanks! |
||
| if try_gzip and broken_hosts_file.exists(): | ||
| with broken_hosts_file.open("r") as f: | ||
| for line in [line.strip() for line in f]: | ||
| if line and not line.startswith("#"): | ||
| broken_hosts.append(line) | ||
|
|
||
| attempts: List[Tuple[str, Compression]] = [] | ||
| if compression == Compression.NONE and try_gzip: | ||
| if ( | ||
| compression == Compression.NONE | ||
| and try_gzip | ||
| and urlobj.netloc not in broken_hosts | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ): | ||
| attempts.append((url + ".gz", Compression.GZIP)) | ||
| attempts.append((url, compression)) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Broken HTTP hosts; these servers are known to cause issues when | ||
| # attempting to download gzipped files from them. | ||
|
|
||
| # The EBI server returns a homepage with a 200 status code, | ||
| # instead of a proper 404, for any unknown URL. | ||
| www.ebi.ac.uk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, not so much a fan of a list.. Cant we just try and fail to decompress?