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
7package fastwalk
8
9import (
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.
18func 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 == SkipFiles {
30 skipFiles = true
31 continue
32 }
33 return err
34 }
35 }
36 return nil
37}