Skip to content
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

Fix usage of absolute windows paths with --image-path #17266

Merged
merged 1 commit into from
Jan 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I get what you are doing, might be nice to say that you are ignoring failure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good point, created a follow-up pr for this: #17269

}

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