Merge pull request #5573 from hashicorp/do_5572
clearly state that url is wrong at validation stage of build
This commit is contained in:
commit
baca3e5a1c
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue