simplify FileExistsLocally
This commit is contained in:
parent
55ddbf4765
commit
3ace5bb91b
|
@ -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!"))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue