Skip to content

Commit

Permalink
fastwalk: document that fs.SkipAll is not respected
Browse files Browse the repository at this point in the history
  • Loading branch information
charlievieth committed Aug 31, 2024
1 parent 5a902c7 commit 940d64f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions fastwalk.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ var ErrSkipFiles = errors.New("fastwalk: skip remaining files in directory")
// as an error by any function.
var SkipDir = fs.SkipDir

// TODO: add fs.SkipAll
// TODO(charlie): Look into implementing the fs.SkipAll behavior of
// filepath.Walk and filepath.WalkDir. This may not be possible without taking
// a performance hit.

// DefaultNumWorkers returns the default number of worker goroutines to use in
// [Walk] and is the value of [runtime.GOMAXPROCS](-1) clamped to a range
Expand Down Expand Up @@ -343,7 +345,9 @@ type DirEntry interface {
//
// If walkFn returns the [SkipDir] sentinel error, the directory is skipped.
// If walkFn returns the [ErrSkipFiles] sentinel error, the callback will not
// be called for any other files in the current directory.
// be called for any other files in the current directory. Unlike,
// [filepath.Walk] and [filepath.WalkDir] the [fs.SkipAll] sentinel error is
// not respected.
//
// Unlike [filepath.WalkDir]:
//
Expand Down Expand Up @@ -375,6 +379,9 @@ type DirEntry interface {
// - When walking a directory, walkFn will be called for each non-directory
// entry and directories will be enqueued and visited at a later time or
// by another goroutine.
//
// - The [fs.SkipAll] sentinel error is not respected and not ignored. If the
// WalkDirFunc returns SkipAll then Walk will exit with the error SkipAll.
func Walk(conf *Config, root string, walkFn fs.WalkDirFunc) error {
fi, err := os.Stat(root)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions fastwalk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,15 @@ func TestFastWalkJoinPaths(t *testing.T) {
}
}

func TestSkipAll(t *testing.T) {
err := fastwalk.Walk(nil, ".", func(path string, info fs.DirEntry, err error) error {
return fs.SkipAll
})
if err != fs.SkipAll {
t.Error("Expected fs.SkipAll to be returned got:", err)
}
}

func BenchmarkSortModeString(b *testing.B) {
var s string
for i := 0; i < b.N; i++ {
Expand Down

0 comments on commit 940d64f

Please sign in to comment.