blob: db87941b0b95e6e89902497859c61d00d01405d8 [file] [log] [blame]
package doublestar
// glob is an internal type to store options during globbing.
type glob struct {
failOnIOErrors bool
// GlobOption represents a setting that can be passed to Glob, GlobWalk, and
// FilepathGlob.
type GlobOption func(*glob)
// Construct a new glob object with the given options
func newGlob(opts ...GlobOption) *glob {
g := &glob{}
for _, opt := range opts {
return g
// WithFailOnIOErrors is an option that can be passed to Glob, GlobWalk, or
// FilepathGlob. If passed, doublestar will abort and return IO errors when
// encountered. Note that if the glob pattern references a path that does not
// exist (such as `nonexistent/path/*`), this is _not_ considered an IO error:
// it is considered a pattern with no matches.
func WithFailOnIOErrors() GlobOption {
return func(g *glob) {
g.failOnIOErrors = true
// forwardErrIfFailOnIOErrors is used to wrap the return values of I/O
// functions. When failOnIOErrors is enabled, it will return err; otherwise, it
// always returns nil.
func (g *glob) forwardErrIfFailOnIOErrors(err error) error {
if g.failOnIOErrors {
return err
return nil
func (g *glob) GoString() string {
if g.failOnIOErrors {
return "opts: WithFailOnIOErrors"
return "opts: nil"