Skip to content

Commit

Permalink
Fix usage of absolute windows paths with --image-path
Browse files Browse the repository at this point in the history
Only assume that http(s) scheme URLs (only ones supported by http.Client anyway) are URLs.
Treat everything else as a file path. (Windows paths can look like a URL scheme)

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
  • Loading branch information
n1hility committed Jan 30, 2023
1 parent 1878d04 commit c3566cd
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions pkg/machine/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ func NewGenericDownloader(vmType, vmName, pullPath string) (DistributionDownload
}
dl := Download{}
// Is pullpath a file or url?
getURL, err := url2.Parse(pullPath)
if err != nil {
return nil, err
}
if len(getURL.Scheme) > 0 {
if getURL := supportedURL(pullPath); getURL != nil {
urlSplit := strings.Split(getURL.Path, "/")
imageName = urlSplit[len(urlSplit)-1]
dl.URL = getURL
Expand All @@ -68,6 +64,26 @@ func NewGenericDownloader(vmType, vmName, pullPath string) (DistributionDownload
return gd, nil
}

func supportedURL(path string) (url *url2.URL) {
getURL, err := url2.Parse(path)
if err != nil {
return nil
}

// Check supported scheme. Since URL is passed to net.http, only http
// schemes are supported. Also, windows drive paths can resemble a
// URL, but with a single letter scheme. These values should be
// passed through for interpretation as a file path.
switch getURL.Scheme {
case "http":
fallthrough
case "https":
return getURL
default:
return nil
}
}

func (d Download) getLocalUncompressedFile(dataDir string) string {
var (
extension string
Expand Down

0 comments on commit c3566cd

Please sign in to comment.