diff --git a/builder/virtualbox/ovf/config.go b/builder/virtualbox/ovf/config.go index 77b7ffa0e..ff8080dd7 100644 --- a/builder/virtualbox/ovf/config.go +++ b/builder/virtualbox/ovf/config.go @@ -2,6 +2,7 @@ package ovf import ( "fmt" + "os" "strings" vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common" @@ -101,6 +102,13 @@ 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. + if (len(c.SourcePath) > 7) && (c.SourcePath[:7] == "file://") { + if _, err := os.Stat(c.SourcePath[7:]); err != nil { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("source file needs to exist at time of config validation: %s", err)) + } + } } validMode := false diff --git a/builder/virtualbox/ovf/config_test.go b/builder/virtualbox/ovf/config_test.go index 980c4d4ef..bdab9b763 100644 --- a/builder/virtualbox/ovf/config_test.go +++ b/builder/virtualbox/ovf/config_test.go @@ -65,14 +65,14 @@ 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 { + if err == nil { t.Fatalf("bad: %s", err) } @@ -84,7 +84,7 @@ func TestNewConfig_sourcePath(t *testing.T) { t.Fatalf("bad: %#v", warns) } if err == nil { - t.Fatal("should error") + t.Fatal("Nonexistent source file should be caught in validation") } // Good