1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #23032 from tonistiigi/walk-err-fix

Fix directory walker error checking
This commit is contained in:
Brian Goff 2016-05-27 11:20:45 -04:00
commit 6e721f6432

View file

@ -29,6 +29,16 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
return err return err
} }
return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error { 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 // 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 { if relFilePath, err := filepath.Rel(contextRoot, filePath); err != nil {
return err return err
@ -41,16 +51,6 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
return nil 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 // skip checking if symlinks point to non-existing files, such symlinks can be useful
// also skip named pipes, because they hanging on open // also skip named pipes, because they hanging on open
if f.Mode()&(os.ModeSymlink|os.ModeNamedPipe) != 0 { if f.Mode()&(os.ModeSymlink|os.ModeNamedPipe) != 0 {