urlfetcher: Deal with 'file://' in _LocalURLFetcher()

osinfo-db may contain files pointing to local paths, which will have the
format 'file:///usr/share/...'.

With the current code, virt-install would just bail as it doesn't
understand the 'file://' schema. Let's start using urllib (which is
already imported in the very same file) and parse the URL so both
'file:///usr/share/...' and '/usr/share/...' would work.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
This commit is contained in:
Fabiano Fidêncio
2019-10-02 11:58:34 -04:00
committed by Cole Robinson
parent 96af1de49f
commit 9465da4174
+5 -3
View File
@@ -365,11 +365,13 @@ class _LocalURLFetcher(_URLFetcher):
For grabbing files from a local directory
"""
def _hasFile(self, url):
return os.path.exists(url)
parsed = urllib.parse.urlparse(url)
return os.path.exists(parsed.path)
def _grabber(self, url):
urlobj = open(url, "rb")
size = os.path.getsize(url)
parsed = urllib.parse.urlparse(url)
urlobj = open(parsed.path, "rb")
size = os.path.getsize(parsed.path)
return urlobj, size