Merge pull request #5573 from hashicorp/do_5572

clearly state that url is wrong at validation stage of build
This commit is contained in:
Matthew Hooker 2017-11-13 13:19:29 -08:00 committed by GitHub
commit baca3e5a1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 11 deletions

View File

@ -2,6 +2,8 @@ package ovf
import (
"fmt"
"net/url"
"os"
"strings"
vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common"
@ -101,6 +103,14 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
if err != nil {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is invalid: %s", err))
}
// file must exist now.
fileURL, _ := url.Parse(c.SourcePath)
if fileURL.Scheme == "file" {
if _, err := os.Stat(fileURL.Path); err != nil {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("source file needs to exist at time of config validation: %s", err))
}
}
}
validMode := false

View File

@ -65,15 +65,15 @@ func TestNewConfig_sourcePath(t *testing.T) {
t.Fatalf("should error with empty `source_path`")
}
// Okay, because it gets caught during download
// Want this to fail on validation
c = testConfig(t)
c["source_path"] = "/i/dont/exist"
_, warns, err = NewConfig(c)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil {
t.Fatalf("bad: %s", err)
if err == nil {
t.Fatalf("Nonexistant file should throw a validation error!")
}
// Bad

View File

@ -109,14 +109,6 @@ func DownloadableURL(original string) (string, error) {
// Make sure it is lowercased
url.Scheme = strings.ToLower(url.Scheme)
// This is to work around issue #5927. This can safely be removed once
// we distribute with a version of Go that fixes that bug.
//
// See: https://code.google.com/p/go/issues/detail?id=5927
if url.Path != "" && url.Path[0] != '/' {
url.Path = "/" + url.Path
}
// Verify that the scheme is something we support in our common downloader.
supported := []string{"file", "http", "https"}
found := false