From 81d24e754d48ac8e9f0e4fe02befbf628179da43 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 26 May 2016 14:59:38 -0700 Subject: [PATCH] Fix directory walker error checking Signed-off-by: Tonis Tiigi --- builder/context.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/builder/context.go b/builder/context.go index 1b6e9d04b0..600f42319b 100644 --- a/builder/context.go +++ b/builder/context.go @@ -29,6 +29,16 @@ func ValidateContextDirectory(srcPath string, excludes []string) error { return err } return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error { + if err != nil { + if os.IsPermission(err) { + return fmt.Errorf("can't stat '%s'", filePath) + } + if os.IsNotExist(err) { + return nil + } + return err + } + // skip this directory/file if it's not in the path, it won't get added to the context if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil { return err @@ -41,16 +51,6 @@ func ValidateContextDirectory(srcPath string, excludes []string) error { return nil } - if err != nil { - if os.IsPermission(err) { - return fmt.Errorf("can't stat '%s'", filePath) - } - if os.IsNotExist(err) { - return nil - } - return err - } - // skip checking if symlinks point to non-existing files, such symlinks can be useful // also skip named pipes, because they hanging on open if f.Mode()&(os.ModeSymlink|os.ModeNamedPipe) != 0 {