walk

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: GPL-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package walk does a concurrent file system traversal and returns each entry. Callers can filter the returned entries via `Options` or a caller provided `Filter` function. This library uses all the available CPUs (as returned by `runtime.NumCPU()`) to maximize concurrency of the file tree traversal.

This library can detect mount point crossings, follow symlinks and also return extended attributes (xattr(7)).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(names []string, opt Options) (chan *fio.Info, chan error)

Walk traverses the entries in 'names' in a concurrent fashion and returns results in a channel of *fio.Info. The caller must service the channel. Any errors encountered during the walk are returned in the error channel.

func WalkFunc

func WalkFunc(names []string, opt Options, apply func(fi *fio.Info) error) error

WalkFunc traverses the entries in 'names' in a concurrent fashion and calls 'apply' for entries that match criteria in 'opt'. The apply function must be concurrency-safe ie it will be called concurrently from multiple go-routines. Any errors reported by 'apply' will be returned from WalkFunc().

Types

type Error added in v0.4.0

type Error struct {
	Op   string
	Name string
	Err  error
}

Error represents the errors returned by CloneFile, CloneMetadata and UpdateMetadata

func (*Error) Error added in v0.4.0

func (e *Error) Error() string

Error returns a string representation of Error

func (*Error) Unwrap added in v0.4.0

func (e *Error) Unwrap() error

Unwrap returns the underlying wrapped error

type Options

type Options struct {
	// Number of go-routines to use; if not set (ie 0),
	// Walk() will use the max available cpus
	Concurrency int

	// Follow symlinks if set
	FollowSymlinks bool

	// stay within the same file-system
	OneFS bool

	// Ignore duplicate inodes. Turning this on
	// suppresses entries with hardlink count greater
	// than 1 - for those entries, only the first encountered
	// entry is output.
	IgnoreDuplicateInode bool

	// Types of entries to return
	Type Type

	// Excludes is a list of shell-glob patterns to exclude from
	// the file-system traversal. In a sense it is an "input filter" -
	// for example, excluded directories are not descended.
	// The matching is done on the basename component of the pathname.
	Excludes []string

	// Filter is an optional caller provided callback to similarly
	// exclude entries from further traversal.
	// This function must return True if this entry should
	// no longer be processed. ie filtered out.
	Filter func(fi *fio.Info) (bool, error)
}

Options control the behavior of the filesystem walk.

type Type

type Type uint

Type is an output filter that can be bitwise OR'd. It denotes the types of file system entries that will be *returned* to the caller.

const (
	FILE    Type = 1 << iota // regular file
	DIR                      // directory
	SYMLINK                  // symbolic link
	DEVICE                   // device special file (blk and char)
	SPECIAL                  // other special files

	// This is a short cut for "give me all entries"
	ALL = FILE | DIR | SYMLINK | DEVICE | SPECIAL
)

func (Type) String

func (t Type) String() string

Stringer for walk filter Type

Jump to

Keyboard shortcuts

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