Documentation
¶
Index ¶
- Variables
- func IsDir(mode os.FileMode) bool
- func IsFile(mode os.FileMode) bool
- func IsSymlink(mode os.FileMode) bool
- func Mtime(fileInfo os.FileInfo) (time.Time, error)
- func Size(fileInfo os.FileInfo) int64
- type Algorithm
- type File
- type Path
- func (p *Path) Chmod(mode os.FileMode) error
- func (p *Path) Chtimes(atime time.Time, mtime time.Time) error
- func (p *Path) Clean() *Path
- func (p *Path) Copy(other *Path) (int64, error)
- func (p *Path) Create() (File, error)
- func (p *Path) DeepEquals(other *Path) (bool, error)
- func (p *Path) DirExists() (bool, error)
- func (p *Path) Equals(other *Path) bool
- func (p *Path) Exists() (bool, error)
- func (p *Path) FileContainsAnyBytes(subslices [][]byte) (bool, error)
- func (p *Path) FileContainsBytes(subslice []byte) (bool, error)
- func (p *Path) Fs() afero.Fs
- func (p *Path) GetLatest() (*Path, error)
- func (p *Path) Glob(pattern string) ([]*Path, error)
- func (p *Path) IsAbsolute() bool
- func (p *Path) IsDir() (bool, error)
- func (p *Path) IsEmpty() (bool, error)
- func (p *Path) IsFile() (bool, error)
- func (p *Path) IsSymlink() (bool, error)
- func (p *Path) Join(elems ...string) *Path
- func (p *Path) JoinPath(path *Path) *Path
- func (p *Path) Lstat() (os.FileInfo, error)
- func (p *Path) Mkdir() error
- func (p *Path) MkdirAll() error
- func (p *Path) MkdirAllMode(perm os.FileMode) error
- func (p *Path) MkdirMode(perm os.FileMode) error
- func (p *Path) Mtime() (time.Time, error)
- func (p *Path) Name() string
- func (p *Path) Open() (*File, error)
- func (p *Path) OpenFile(flag int) (*File, error)
- func (p *Path) OpenFileMode(flag int, perm os.FileMode) (*File, error)
- func (p *Path) Parent() *Path
- func (p *Path) Parts() []string
- func (p *Path) ReadDir() ([]*Path, error)
- func (p *Path) ReadFile() ([]byte, error)
- func (p *Path) Readlink() (*Path, error)
- func (p *Path) RelativeTo(other *Path) (*Path, error)
- func (p *Path) RelativeToStr(other string) (*Path, error)
- func (p *Path) Remove() error
- func (p *Path) RemoveAll() error
- func (p *Path) Rename(target *Path) error
- func (p *Path) RenameStr(newname string) error
- func (p *Path) ResolveAll() (*Path, error)
- func (p *Path) SafeWriteReader(r io.Reader) error
- func (p *Path) Size() (int64, error)
- func (p *Path) Stat() (os.FileInfo, error)
- func (p *Path) String() string
- func (p *Path) Symlink(target *Path) error
- func (p *Path) SymlinkStr(target string) error
- func (p *Path) WriteFile(data []byte) error
- func (p *Path) WriteFileMode(data []byte, perm os.FileMode) error
- func (p *Path) WriteReader(r io.Reader) error
- type PathOpts
- type Walk
- type WalkFunc
- type WalkOpts
- type WalkOptsFunc
- func WalkAlgorithm(algo Algorithm) WalkOptsFunc
- func WalkDepth(depth int) WalkOptsFunc
- func WalkFollowSymlinks(follow bool) WalkOptsFunc
- func WalkMaximumFileSize(size int64) WalkOptsFunc
- func WalkMinimumFileSize(size int64) WalkOptsFunc
- func WalkSortChildren(value bool) WalkOptsFunc
- func WalkVisitDirs(value bool) WalkOptsFunc
- func WalkVisitFiles(value bool) WalkOptsFunc
- func WalkVisitSymlinks(value bool) WalkOptsFunc
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDoesNotImplement indicates that the afero filesystem doesn't // implement the required interface. ErrDoesNotImplement = fmt.Errorf("doesn't implement required interface") // ErrInfoIsNil indicates that a nil os.FileInfo object was provided ErrInfoIsNil = fmt.Errorf("provided os.Info object was nil") // ErrInvalidAlgorithm specifies that an unknown algorithm was given for Walk ErrInvalidAlgorithm = fmt.Errorf("invalid algorithm specified") // ErrLstatNotPossible specifies that the filesystem does not support lstat-ing ErrLstatNotPossible = fmt.Errorf("lstat is not possible") // ErrRelativeTo indicates that we could not make one path relative to another ErrRelativeTo = fmt.Errorf("failed to make path relative to other") // ErrSkipSubtree indicates to the walk function that the current subtree of // directories should be skipped. It's recommended to only use this error // with the AlgorithmPreOrderDepthFirst algorithm, as many other walk algorithms // will not respect this error due to the nature of the ordering in which the // algorithms visit each node of the filesystem tree. ErrWalkSkipSubtree = fmt.Errorf("skip subtree: %w", errWalkControl) // ErrStopWalk indicates to the Walk function that the walk should be aborted. // DEPRECATED: Use ErrWalkStop ErrStopWalk = ErrWalkStop // ErrWalkStop indicates to the Walk function that the walk should be aborted. ErrWalkStop = fmt.Errorf("stop filesystem walk: %w", errWalkControl) )
var DefaultDirMode = os.FileMode(0o755)
DefaultDirMode is the default mode that will be applied to new directories
var DefaultFileMode = os.FileMode(0o644)
DefaultFileMode is the file mode that will be applied to new pathlib files
Functions ¶
func IsDir ¶ added in v0.5.0
IsDir returns whether or not the os.FileMode object represents a directory.
func IsFile ¶ added in v0.5.0
IsFile returns whether or not the file described by the given os.FileMode is a regular file.
func IsSymlink ¶ added in v0.5.0
IsSymlink returns true if the file described by the given os.FileMode describes a symlink.
Types ¶
type Algorithm ¶ added in v0.7.0
type Algorithm int
Algorithm represents the walk algorithm that will be performed.
const ( // AlgorithmBasic is a walk algorithm. It iterates over filesystem objects in the // order in which they are returned by the operating system. It guarantees no // ordering of any kind. It will recurse into subdirectories as soon as it encounters them, // and will continue iterating the remaining children after the recursion is complete. // It behaves as a quasi-DFS algorithm. AlgorithmBasic Algorithm = iota // AlgorithmDepthFirst is a walk algorithm. More specifically, it is a post-order // depth first search whereby subdirectories are recursed into before // visiting the children of the current directory. // DEPRECATED: Use AlgorithmPostOrderDepthFirst AlgorithmDepthFirst // AlgorithmPostOrderDepthFirst is a walk algorithm that recurses into all of its children // before visiting any of a node's elements. AlgorithmPostOrderDepthFirst // AlgorithmPreOrderDepthFirst is a walk algorithm. It visits all of a node's elements // before recursing into its children. AlgorithmPreOrderDepthFirst )
type File ¶ added in v0.3.0
File represents a file in the filesystem. It inherits the afero.File interface but might also include additional functionality.
type Path ¶
type Path struct { // DefaultFileMode is the mode that is used when creating new files in functions // that do not accept os.FileMode as a parameter. DefaultFileMode os.FileMode // DefaultDirMode is the mode that will be used when creating new directories DefaultDirMode os.FileMode // Sep is the seperator used in path calculations. By default this is set to // os.PathSeparator. Sep string // contains filtered or unexported fields }
Path is an object that represents a path
func Glob ¶
Glob returns all of the path objects matched by the given pattern inside of the afero filesystem.
func NewPathAfero
deprecated
func (*Path) Clean ¶ added in v0.12.0
Clean returns a new object that is a lexically-cleaned version of Path.
func (*Path) Copy ¶ added in v0.16.0
Copy copies the path to another path using io.Copy. Returned is the number of bytes copied and any error values. The destination file is truncated if it exists, and is created if it does not exist.
func (*Path) Create ¶ added in v0.2.0
Create creates a file if possible, returning the file and an error, if any happens.
func (*Path) DeepEquals ¶ added in v0.9.0
DeepEquals returns whether or not the path pointed to by other has the same resolved filepath as self.
func (*Path) DirExists ¶ added in v0.2.0
DirExists returns whether or not the path represents a directory that exists
func (*Path) Equals ¶
Equals returns whether or not the object's path is identical to other's, in a shallow sense. It simply checks for equivalence in the unresolved Paths() of each object.
func (*Path) FileContainsAnyBytes ¶ added in v0.2.0
FileContainsAnyBytes returns whether or not the path contains any of the listed bytes.
func (*Path) FileContainsBytes ¶ added in v0.2.0
FileContainsBytes returns whether or not the given file contains the bytes
func (*Path) GetLatest ¶
GetLatest returns the file or directory that has the most recent mtime. Only works if this path is a directory and it exists. If the directory is empty, the returned Path object will be nil.
func (*Path) IsAbsolute ¶
IsAbsolute returns whether or not the path is an absolute path. This is determined by checking if the path starts with a slash.
func (*Path) IsSymlink ¶
IsSymlink returns true if the given path is a symlink. Fails if the filesystem doesn't implement afero.Lstater.
func (*Path) Join ¶
Join joins the current object's path with the given elements and returns the resulting Path object.
func (*Path) JoinPath ¶ added in v0.4.0
JoinPath is the same as Join() except it accepts a path object
func (*Path) Lstat ¶ added in v0.5.0
Lstat lstat's the path if the underlying afero filesystem supports it. If the filesystem does not support afero.Lstater, or if the filesystem implements afero.Lstater but returns false for the "lstat called" return value.
A nil os.FileInfo is returned on errors.
func (*Path) MkdirAllMode ¶ added in v0.11.0
MkdirAllMode makes all of the directories up to, and including, the given path.
func (*Path) MkdirMode ¶ added in v0.11.0
MkdirMode makes the current dir. If the parents don't exist, an error is returned.
func (*Path) Open ¶ added in v0.2.0
Open opens a file for read-only, returning it or an error, if any happens.
func (*Path) OpenFile ¶ added in v0.2.0
OpenFile opens a file using the given flags. See the list of flags at: https://golang.org/pkg/os/#pkg-constants
func (*Path) OpenFileMode ¶ added in v0.12.0
OpenFileMode opens a file using the given flags and the given mode. See the list of flags at: https://golang.org/pkg/os/#pkg-constants
func (*Path) ReadDir ¶
ReadDir reads the current path and returns a list of the corresponding Path objects. This function differs from os.Readdir in that it does not call Stat() on the files. Instead, it calls Readdirnames which is less expensive and does not force the caller to make expensive Stat calls.
func (*Path) ReadFile ¶
ReadFile reads the given path and returns the data. If the file doesn't exist or is a directory, an error is returned.
func (*Path) Readlink ¶ added in v0.12.0
Readlink returns the target path of a symlink.
This will fail if the underlying afero filesystem does not implement afero.LinkReader.
func (*Path) RelativeTo ¶
RelativeTo computes a relative version of path to the other path. For instance, if the object is /path/to/foo.txt and you provide /path/ as the argment, the returned Path object will represent to/foo.txt.
func (*Path) RelativeToStr ¶ added in v0.12.0
RelativeToStr computes a relative version of path to the other path. For instance, if the object is /path/to/foo.txt and you provide /path/ as the argment, the returned Path object will represent to/foo.txt.
func (*Path) ResolveAll ¶ added in v0.4.0
ResolveAll canonicalizes the path by following every symlink in every component of the given path recursively. The behavior should be identical to the `readlink -f` command from POSIX OSs. This will fail if the underlying afero filesystem does not implement afero.LinkReader. The path will be returned unchanged on errors.
func (*Path) SafeWriteReader ¶ added in v0.2.0
SafeWriteReader is the same as WriteReader but checks to see if file/directory already exists.
func (*Path) Size ¶ added in v0.5.0
Size returns the size of the object. Fails if the object doesn't exist.
func (*Path) Symlink ¶
Symlink symlinks to the target location. This will fail if the underlying afero filesystem does not implement afero.Linker.
func (*Path) SymlinkStr ¶ added in v0.12.0
SymlinkStr symlinks to the target location. This will fail if the underlying afero filesystem does not implement afero.Linker.
func (*Path) WriteFile ¶
WriteFile writes the given data to the path (if possible). If the file exists, the file is truncated. If the file is a directory, or the path doesn't exist, an error is returned.
func (*Path) WriteFileMode ¶ added in v0.12.0
WriteFileMode writes the given data to the path (if possible). If the file exists, the file is truncated. If the file is a directory, or the path doesn't exist, an error is returned.
type PathOpts ¶ added in v0.17.0
type PathOpts func(p *Path)
func PathWithAfero ¶ added in v0.17.0
func PathWithSeperator ¶ added in v0.17.0
type Walk ¶ added in v0.6.0
type Walk struct { Opts *WalkOpts // contains filtered or unexported fields }
Walk is an object that handles walking through a directory tree
func NewWalk ¶ added in v0.6.0
func NewWalk(root *Path, opts ...WalkOptsFunc) (*Walk, error)
NewWalk returns a new Walk struct with default values applied
func NewWalkWithOpts ¶ added in v0.6.0
NewWalkWithOpts returns a Walk object with the given WalkOpts applied
type WalkFunc ¶ added in v0.6.0
WalkFunc is the function provided to the Walk function for each directory.
type WalkOpts ¶ added in v0.6.0
type WalkOpts struct { // Depth defines how far down a directory we should recurse. A value of -1 means // infinite depth. 0 means only the direct children of root will be returned, etc. Depth int // Algorithm specifies the algoritm that the Walk() function should use to // traverse the directory. Algorithm Algorithm // FollowSymlinks defines whether symlinks should be dereferenced or not. If True, // the symlink itself will never be returned to WalkFunc, but rather whatever it // points to. FollowSymlinks bool // MinimumFileSize specifies the minimum size of a file for visitation. // If negative, there is no minimum size. MinimumFileSize int64 // MaximumFileSize specifies the maximum size of a file for visitation. // If negative, there is no maximum size. MaximumFileSize int64 // VisitFiles specifies that we should visit regular files during // the walk. VisitFiles bool // VisitDirs specifies that we should visit directories during the walk. VisitDirs bool // VisitSymlinks specifies that we should visit symlinks during the walk. VisitSymlinks bool // SortChildren causes all children of a path to be lexigraphically sorted before // being sent to the WalkFunc. SortChildren bool }
WalkOpts is the struct that defines how a walk should be performed
func DefaultWalkOpts ¶ added in v0.6.0
func DefaultWalkOpts() *WalkOpts
DefaultWalkOpts returns the default WalkOpts struct used when walking a directory.
func (*WalkOpts) MeetsMaximumSize ¶ added in v0.8.0
MeetsMaximumSize returns whether size is less than or equal to the maximum specified.
func (*WalkOpts) MeetsMinimumSize ¶ added in v0.8.0
MeetsMinimumSize returns whether size is at least the minimum specified.
type WalkOptsFunc ¶ added in v0.13.0
type WalkOptsFunc func(config *WalkOpts)
func WalkAlgorithm ¶ added in v0.13.0
func WalkAlgorithm(algo Algorithm) WalkOptsFunc
func WalkDepth ¶ added in v0.13.0
func WalkDepth(depth int) WalkOptsFunc
func WalkFollowSymlinks ¶ added in v0.13.0
func WalkFollowSymlinks(follow bool) WalkOptsFunc
func WalkMaximumFileSize ¶ added in v0.13.0
func WalkMaximumFileSize(size int64) WalkOptsFunc
func WalkMinimumFileSize ¶ added in v0.13.0
func WalkMinimumFileSize(size int64) WalkOptsFunc
func WalkSortChildren ¶ added in v0.18.0
func WalkSortChildren(value bool) WalkOptsFunc
func WalkVisitDirs ¶ added in v0.13.0
func WalkVisitDirs(value bool) WalkOptsFunc
func WalkVisitFiles ¶ added in v0.13.0
func WalkVisitFiles(value bool) WalkOptsFunc
func WalkVisitSymlinks ¶ added in v0.13.0
func WalkVisitSymlinks(value bool) WalkOptsFunc