From 22d1322bd9e4612fc73a1132b04a35874b82804e Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Thu, 26 Jan 2017 16:32:21 -0800 Subject: [PATCH] always check for an error first when walking a path --- builder/hyperv/common/artifact.go | 5 ++++- builder/parallels/common/artifact.go | 5 ++++- builder/qemu/builder.go | 5 ++++- builder/virtualbox/common/artifact.go | 3 +++ builder/vmware/common/artifact.go | 6 ++++-- common/step_create_floppy.go | 3 +++ common/step_create_floppy_test.go | 3 +++ 7 files changed, 25 insertions(+), 5 deletions(-) diff --git a/builder/hyperv/common/artifact.go b/builder/hyperv/common/artifact.go index 2baeb2d62..63b123eee 100644 --- a/builder/hyperv/common/artifact.go +++ b/builder/hyperv/common/artifact.go @@ -23,11 +23,14 @@ type artifact struct { func NewArtifact(dir string) (packer.Artifact, error) { files := make([]string, 0, 5) visit := func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } if !info.IsDir() { files = append(files, path) } - return err + return nil } if err := filepath.Walk(dir, visit); err != nil { diff --git a/builder/parallels/common/artifact.go b/builder/parallels/common/artifact.go index bd490f9ac..04961974b 100644 --- a/builder/parallels/common/artifact.go +++ b/builder/parallels/common/artifact.go @@ -28,6 +28,9 @@ type artifact struct { func NewArtifact(dir string) (packer.Artifact, error) { files := make([]string, 0, 5) visit := func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } for _, unnecessaryFile := range unnecessaryFiles { if unnecessary, _ := regexp.MatchString(unnecessaryFile, path); unnecessary { return os.RemoveAll(path) @@ -38,7 +41,7 @@ func NewArtifact(dir string) (packer.Artifact, error) { files = append(files, path) } - return err + return nil } if err := filepath.Walk(dir, visit); err != nil { diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index 862ef7918..3e2b79b11 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -444,11 +444,14 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe // Compile the artifact list files := make([]string, 0, 5) visit := func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } if !info.IsDir() { files = append(files, path) } - return err + return nil } if err := filepath.Walk(b.config.OutputDir, visit); err != nil { diff --git a/builder/virtualbox/common/artifact.go b/builder/virtualbox/common/artifact.go index 9755c7a44..c28fb6c59 100644 --- a/builder/virtualbox/common/artifact.go +++ b/builder/virtualbox/common/artifact.go @@ -23,6 +23,9 @@ type artifact struct { func NewArtifact(dir string) (packer.Artifact, error) { files := make([]string, 0, 5) visit := func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } if !info.IsDir() { files = append(files, path) } diff --git a/builder/vmware/common/artifact.go b/builder/vmware/common/artifact.go index 710ed9aad..15d797f3f 100644 --- a/builder/vmware/common/artifact.go +++ b/builder/vmware/common/artifact.go @@ -23,11 +23,13 @@ type localArtifact struct { func NewLocalArtifact(dir string) (packer.Artifact, error) { files := make([]string, 0, 5) visit := func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } if !info.IsDir() { files = append(files, path) } - - return err + return nil } if err := filepath.Walk(dir, visit); err != nil { diff --git a/common/step_create_floppy.go b/common/step_create_floppy.go index 9b5e7d812..eb0a6057e 100644 --- a/common/step_create_floppy.go +++ b/common/step_create_floppy.go @@ -114,6 +114,9 @@ func (s *StepCreateFloppy) Run(state multistep.StateBag) multistep.StepAction { var crawlDirectoryFiles []string crawlDirectory := func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } if !info.IsDir() { crawlDirectoryFiles = append(crawlDirectoryFiles, path) ui.Message(fmt.Sprintf("Adding file: %s", path)) diff --git a/common/step_create_floppy_test.go b/common/step_create_floppy_test.go index fcac9a891..cfdf3989e 100644 --- a/common/step_create_floppy_test.go +++ b/common/step_create_floppy_test.go @@ -21,6 +21,9 @@ const TestFixtures = "test-fixtures" func getDirectory(path string) []string { var result []string walk := func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } if info.IsDir() && !strings.HasSuffix(path, "/") { path = path + "/" }