github.com/jd-ly/tools@v0.5.7/internal/fastwalk/fastwalk_portable.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build appengine !linux,!darwin,!freebsd,!openbsd,!netbsd 6 7 package fastwalk 8 9 import ( 10 "io/ioutil" 11 "os" 12 ) 13 14 // readDir calls fn for each directory entry in dirName. 15 // It does not descend into directories or follow symlinks. 16 // If fn returns a non-nil error, readDir returns with that error 17 // immediately. 18 func readDir(dirName string, fn func(dirName, entName string, typ os.FileMode) error) error { 19 fis, err := ioutil.ReadDir(dirName) 20 if err != nil { 21 return err 22 } 23 skipFiles := false 24 for _, fi := range fis { 25 if fi.Mode().IsRegular() && skipFiles { 26 continue 27 } 28 if err := fn(dirName, fi.Name(), fi.Mode()&os.ModeType); err != nil { 29 if err == ErrSkipFiles { 30 skipFiles = true 31 continue 32 } 33 return err 34 } 35 } 36 return nil 37 }