ceph-csi/e2e/vendor/github.com/karrick/godirwalk/scanner.go
Niels de Vos f87d06ed85 build: move e2e dependencies into e2e/go.mod
Several packages are only used while running the e2e suite. These
packages are less important to update, as the they can not influence the
final executable that is part of the Ceph-CSI container-image.

By moving these dependencies out of the main Ceph-CSI go.mod, it is
easier to identify if a reported CVE affects Ceph-CSI, or only the
testing (like most of the Kubernetes CVEs).

Signed-off-by: Niels de Vos <ndevos@ibm.com>
2025-03-04 17:43:49 +01:00

45 lines
953 B
Go

package godirwalk
import "sort"
type scanner interface {
Dirent() (*Dirent, error)
Err() error
Name() string
Scan() bool
}
// sortedScanner enumerates through a directory's contents after reading the
// entire directory and sorting the entries by name. Used by walk to simplify
// its implementation.
type sortedScanner struct {
dd []*Dirent
de *Dirent
}
func newSortedScanner(osPathname string, scratchBuffer []byte) (*sortedScanner, error) {
deChildren, err := ReadDirents(osPathname, scratchBuffer)
if err != nil {
return nil, err
}
sort.Sort(deChildren)
return &sortedScanner{dd: deChildren}, nil
}
func (d *sortedScanner) Err() error {
d.dd, d.de = nil, nil
return nil
}
func (d *sortedScanner) Dirent() (*Dirent, error) { return d.de, nil }
func (d *sortedScanner) Name() string { return d.de.name }
func (d *sortedScanner) Scan() bool {
if len(d.dd) > 0 {
d.de, d.dd = d.dd[0], d.dd[1:]
return true
}
return false
}