Skip to content

Commit 81d24e7

Browse files
committed
Fix directory walker error checking
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent ef89891 commit 81d24e7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

builder/context.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
2929
return err
3030
}
3131
return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error {
32+
if err != nil {
33+
if os.IsPermission(err) {
34+
return fmt.Errorf("can't stat '%s'", filePath)
35+
}
36+
if os.IsNotExist(err) {
37+
return nil
38+
}
39+
return err
40+
}
41+
3242
// skip this directory/file if it's not in the path, it won't get added to the context
3343
if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil {
3444
return err
@@ -41,16 +51,6 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
4151
return nil
4252
}
4353

44-
if err != nil {
45-
if os.IsPermission(err) {
46-
return fmt.Errorf("can't stat '%s'", filePath)
47-
}
48-
if os.IsNotExist(err) {
49-
return nil
50-
}
51-
return err
52-
}
53-
5454
// skip checking if symlinks point to non-existing files, such symlinks can be useful
5555
// also skip named pipes, because they hanging on open
5656
if f.Mode()&(os.ModeSymlink|os.ModeNamedPipe) != 0 {

0 commit comments

Comments
 (0)