walk

package
v1.43.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package walk walks directories

Index

Constants

This section is empty.

Variables

View Source
var ErrorCantListR = errors.New("recursive directory listing not available")

ErrorCantListR is returned by WalkR if the underlying Fs isn't capable of doing a recursive listing.

View Source
var ErrorSkipDir = errors.New("skip this directory")

ErrorSkipDir is used as a return value from Walk to indicate that the directory named in the call is to be skipped. It is not returned as an error by any function.

Functions

func GetAll

func GetAll(f fs.Fs, path string, includeAll bool, maxLevel int) (objs []fs.Object, dirs []fs.Directory, err error)

GetAll runs Walk getting all the results

func Walk

func Walk(f fs.Fs, path string, includeAll bool, maxLevel int, fn Func) error

Walk lists the directory.

If includeAll is not set it will use the filters defined.

If maxLevel is < 0 then it will recurse indefinitely, else it will only do maxLevel levels.

It calls fn for each tranche of DirEntries read.

Note that fn will not be called concurrently whereas the directory listing will proceed concurrently.

Parent directories are always listed before their children

This is implemented by WalkR if Config.UseRecursiveListing is true and f supports it and level > 1, or WalkN otherwise.

NB (f, path) to be replaced by fs.Dir at some point

Types

type DirTree

type DirTree map[string]fs.DirEntries

DirTree is a map of directories to entries

func NewDirTree

func NewDirTree(f fs.Fs, path string, includeAll bool, maxLevel int) (DirTree, error)

NewDirTree returns a DirTree filled with the directory listing using the parameters supplied.

If includeAll is not set it will use the filters defined.

If maxLevel is < 0 then it will recurse indefinitely, else it will only do maxLevel levels.

This is implemented by WalkR if Config.UseRecursiveListing is true and f supports it and level > 1, or WalkN otherwise.

NB (f, path) to be replaced by fs.Dir at some point

func (DirTree) Dirs

func (dt DirTree) Dirs() (dirNames []string)

Dirs returns the directories in sorted order

func (DirTree) Find

func (dt DirTree) Find(filePath string) (parentPath string, entry fs.DirEntry)

Find returns the DirEntry for filePath or nil if not found

func (DirTree) Prune

func (dt DirTree) Prune(dirNames map[string]bool) error

Prune remove directories from a directory tree. dirNames contains all directories to remove as keys, with true as values. dirNames will be modified in the function.

func (DirTree) Sort

func (dt DirTree) Sort()

Sort sorts all the Entries

func (DirTree) String

func (dt DirTree) String() string

String emits a simple representation of the DirTree

type Func

type Func func(path string, entries fs.DirEntries, err error) error

Func is the type of the function called for directory visited by Walk. The path argument contains remote path to the directory.

If there was a problem walking to directory named by path, the incoming error will describe the problem and the function can decide how to handle that error (and Walk will not descend into that directory). If an error is returned, processing stops. The sole exception is when the function returns the special value ErrorSkipDir. If the function returns ErrorSkipDir, Walk skips the directory's contents entirely.

type ListRHelper

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

ListRHelper is used in the implementation of ListR to accumulate DirEntries

func NewListRHelper

func NewListRHelper(callback fs.ListRCallback) *ListRHelper

NewListRHelper should be called from ListR with the callback passed in

func (*ListRHelper) Add

func (lh *ListRHelper) Add(entry fs.DirEntry) error

Add an entry to the stored entries and send them if there are more than a certain amount

func (*ListRHelper) Flush

func (lh *ListRHelper) Flush() error

Flush the stored entries (if any) sending them to the callback

Jump to

Keyboard shortcuts

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