2016-07-17 18:47:35 -06:00
|
|
|
// Copyright 2016 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2016-08-15 15:54:39 -06:00
|
|
|
// +build appengine !linux,!darwin,!freebsd,!openbsd,!netbsd
|
2016-07-17 18:47:35 -06:00
|
|
|
|
2018-03-08 14:10:10 -07:00
|
|
|
package fastwalk
|
2016-07-17 18:47:35 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// readDir calls fn for each directory entry in dirName.
|
|
|
|
// It does not descend into directories or follow symlinks.
|
|
|
|
// If fn returns a non-nil error, readDir returns with that error
|
|
|
|
// immediately.
|
|
|
|
func readDir(dirName string, fn func(dirName, entName string, typ os.FileMode) error) error {
|
|
|
|
fis, err := ioutil.ReadDir(dirName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-09-18 13:06:34 -06:00
|
|
|
skipFiles := false
|
2016-07-17 18:47:35 -06:00
|
|
|
for _, fi := range fis {
|
2018-09-18 13:06:34 -06:00
|
|
|
if fi.Mode().IsRegular() && skipFiles {
|
|
|
|
continue
|
|
|
|
}
|
2016-07-17 18:47:35 -06:00
|
|
|
if err := fn(dirName, fi.Name(), fi.Mode()&os.ModeType); err != nil {
|
2019-11-20 20:43:00 -07:00
|
|
|
if err == ErrSkipFiles {
|
2018-09-18 13:06:34 -06:00
|
|
|
skipFiles = true
|
|
|
|
continue
|
|
|
|
}
|
2016-07-17 18:47:35 -06:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|