Bugfix: fetching oddly-named resources from local mirrors (#23300)

Spack uses curl to fetch URL resources. For locally-stored resources
it uses curl's file protocol; when using this protocol, curl expects
that the URL encoding conforms to RFC 3986 (which reserves characters
like '?' and '=' for special use).

We were not performing this encoding, and found a resource where
curl was interpreting this in an unfavorable way (succeeding, but
producing an empty file). This commit properly encodes URLs when
using curl's file protocol.

This error did not likely come up before because in most contexts
Spack was either fetching via http or it was using URLs without
offending characters (for example, the sha-based URLs in mirrors
never contain these characters).
This commit is contained in:
Michael Kuhn 2021-05-19 00:26:49 +02:00 committed by GitHub
parent ba68cbc694
commit 9410d99153
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -292,7 +292,15 @@ def mirror_id(self):
@property
def candidate_urls(self):
return [self.url] + (self.mirrors or [])
urls = []
for url in [self.url] + (self.mirrors or []):
if url.startswith('file://'):
path = urllib_parse.quote(url[len('file://'):])
url = 'file://' + path
urls.append(url)
return urls
@_needs_stage
def fetch(self):