From 3ace5bb91becc645dd8acfa0fca0199e8ceed115 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 10 Jan 2018 16:11:17 -0800 Subject: [PATCH] simplify FileExistsLocally --- builder/virtualbox/ovf/config.go | 6 +++--- common/config.go | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/builder/virtualbox/ovf/config.go b/builder/virtualbox/ovf/config.go index ab8eccc41..41a013ebd 100644 --- a/builder/virtualbox/ovf/config.go +++ b/builder/virtualbox/ovf/config.go @@ -101,10 +101,10 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { if err != nil { errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is invalid: %s", err)) } - _, err := common.FileExistsLocally(c.SourcePath) - if err != nil { + fileOK := common.FileExistsLocally(c.SourcePath) + if !fileOK { packer.MultiErrorAppend(errs, - fmt.Errorf("Source file needs to exist at time of config validation: %s", err)) + fmt.Errorf("Source file needs to exist at time of config validation!")) } } diff --git a/common/config.go b/common/config.go index 2b0de0c5c..7bef253ee 100644 --- a/common/config.go +++ b/common/config.go @@ -135,16 +135,14 @@ func DownloadableURL(original string) (string, error) { // // myFile, err = common.DownloadableURL(c.SourcePath) // ... -// fileExists, err := common.StatURL(myFile) +// fileExists := common.StatURL(myFile) // possible output: -// true, nil -- should occur if the file is present -// false, nil -- should occur if the file is not present, but is not supposed to -// be (e.g. the schema is http://, not file://) -// true, error -- shouldn't occur ever -// false, error -- should occur if there was an error stating the file, so the +// true -- should occur if the file is present, or if the file is not present, +// but is not supposed to be (e.g. the schema is http://, not file://) +// false -- should occur if there was an error stating the file, so the // file is not present when it should be. -func FileExistsLocally(original string) (bool, error) { +func FileExistsLocally(original string) bool { // original should be something like file://C:/my/path.iso fileURL, _ := url.Parse(original) @@ -163,11 +161,10 @@ func FileExistsLocally(original string) (bool, error) { } _, err := os.Stat(filePath) if err != nil { - err = fmt.Errorf("could not stat file: %s\n", err) - return fileExists, err + return fileExists } else { fileExists = true } } - return fileExists, nil + return fileExists }