Skip to content

Commit

Permalink
fix FileExistsLocally
Browse files Browse the repository at this point in the history
  • Loading branch information
SwampDragons committed Jan 4, 2018
1 parent 4f3b470 commit 0ff848a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion builder/virtualbox/ovf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
if err != nil {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is invalid: %s", err))
}
fileExists, err := common.FileExistsLocally(c.SourcePath)
_, err := common.FileExistsLocally(c.SourcePath)
if err != nil {
packer.MultiErrorAppend(errs,
fmt.Errorf("Source file needs to exist at time of config validation: %s", err))
Expand Down
14 changes: 8 additions & 6 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,20 @@ func DownloadableURL(original string) (string, error) {
func FileExistsLocally(original string) (bool, error) {
fileURL, _ := url.Parse(original)
fileExists := false
err := nil

if fileURL.Scheme == "file" {
// Remove forward slash on absolute Windows file URLs before processing
if runtime.GOOS == "windows" && len(fileURL.Path) > 0 && fileURL.Path[0] == '/' {
filePath := fileURL.Path[1:]
filePath := fileURL.Path
if runtime.GOOS == "windows" && len(filePath) > 0 && filePath[0] == '/' {
filePath = filePath[1:]
}
if _, err := os.Stat(filePath); err != nil {
err = fmt.Errorf("source file needs to exist at time of config validation: %s", err)
_, err := os.Stat(filePath)
if err != nil {
err = fmt.Errorf("could not stat file %s", err)
return fileExists, err
} else {
fileExists = true
}
}
return fileExists, err
return fileExists, nil
}

0 comments on commit 0ff848a

Please sign in to comment.