filesystem

package
v0.0.0-...-90889cf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSkip = fmt.Errorf("skip file or folder")

ErrSkip can be returned to indicate that the current file or folder should be skipped from any further traversal.

Functions

func CutPath

func CutPath(path string) (segment string, remainder string)

CutPath tries to extract the first segment from the path. If the path does not contain a separator, then the returned remainder is empty.

func Glob

func Glob(pattern string) string

Glob prepends the glob prefix to the specified pattern.

func IsGlob

func IsGlob(pattern string) bool

IsGlob checks whether the specified pattern is a candidate to be a glob. In general, that means it has the glob prefix, which is `*/` . If this method returns true, this does not mean that the glob pattern itself is valid.

func Pattern

func Pattern(glob string) string

Pattern returns the glob pattern from the specified glob string.

func Traverse

func Traverse(root string, callback TraverseFunc)

Traverse attempts to simplify file traversal.

The underlying filepath.WalkDir only works well for directories as root elements. Passing a file as root changes the contract substantially making it hard on the client.

Types

type AbsolutePath

type AbsolutePath = string

AbsolutePath is a string that holds an absolute path.

func ToAbsolutePath

func ToAbsolutePath(path string) (AbsolutePath, error)

ToAbsolutePath converts the specified path to absolute.

type FilterTree

type FilterTree struct {
	// contains filtered or unexported fields
}

FilterTree is a data structure that can be used to mark specific filesystem paths as accepted and others as rejected. This can also be achieved through global glob patterns.

The structure then provides a means through which one can test whether a given file path is accepted or rejected by the filter.

func NewFilterTree

func NewFilterTree() *FilterTree

NewFilterTree creates a new empty FilterTree instance.

func (*FilterTree) AcceptGlob

func (t *FilterTree) AcceptGlob(glob string)

AcceptGlob requests that sub-paths of a path segment that matches the specified glob should be accepted.

func (*FilterTree) AcceptPath

func (t *FilterTree) AcceptPath(path AbsolutePath)

AcceptPath requests that the specified path be accepted.

func (*FilterTree) IsAccepted

func (t *FilterTree) IsAccepted(path AbsolutePath) bool

IsAccepted returns whether the specified path is allowed by this filter.

func (*FilterTree) RejectGlob

func (t *FilterTree) RejectGlob(glob string)

RejectGlob requests that sub-paths of a path segment that matches the specified glob should not be accepted.

func (*FilterTree) RejectPath

func (t *FilterTree) RejectPath(path AbsolutePath)

RejectPath requests that the specified path be rejected.

func (*FilterTree) RootPaths

func (t *FilterTree) RootPaths() []AbsolutePath

RootPaths returns the top-most paths that are accepted.

type TraverseFunc

type TraverseFunc func(path string, isDir bool, err error) error

TraverseFunc is called for each visited folder.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL