pfs

package
v0.4.29 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: ISC Imports: 18 Imported by: 3

Documentation

Overview

Package pfs provides file-system related functions

Index

Constants

View Source
const (
	// AllModeBits is all known github.com/fsnotify/fsevents.EventFlags
	AllModeBits fs.FileMode = fs.ModeDir | fs.ModeAppend | fs.ModeExclusive |
		fs.ModeTemporary | fs.ModeSymlink | fs.ModeDevice | fs.ModeNamedPipe |
		fs.ModeSocket | fs.ModeSetuid | fs.ModeSetgid | fs.ModeCharDevice |
		fs.ModeSticky | fs.ModeIrregular
)

Variables

View Source
var EndListing = errors.New("endListing")

Functions

func Abs added in v0.4.23

func Abs(dir string) (out string)

Abs ensures a file system path is fully qualified. Abs is single-return-value and panics on troubles

func AbsEval

func AbsEval(path string) (p string, err error)

AbsEval makes path absolute and resolves symlinks

func Dirs

func Dirs(dir string, callback ...func(dir string) (err error)) (dirs []string, err error)

Dirs retrieves absolute paths to all directories, while following symlinks, from initial dir argument. callback: cb is 6–58% faster than slice, results are found faster, and it can be canceled midway. if callback blocks, not good…

func Elems added in v0.4.26

func Elems(path string) (dirs []string, file string)

Elems splits a path into a list of directory names and base filename part. if path is absolute, dirs[0] is "/". if there is no separator in path, dirs is empty. if path is empty string, dirs is empty and file is empty string.

func EnsureDirectory

func EnsureDirectory(directory string, dirMode fs.FileMode)

use 0 for default file mode owner rwx

func Exists

func Exists(path string) (fileInfo fs.FileInfo)

Exists determines if a path exists If the path exists, fileInfo is non-nil if the path does not exist, fileInfo is nil panic on troubles

func GetModeBitValues

func GetModeBitValues() (s string)

func IsDirectory

func IsDirectory(path string, flags IsDirectoryArg) (isDirectory bool, err error)

func IsEmptyDirectory

func IsEmptyDirectory(path string, ignoreENOENT ...bool) (isEmpty bool)

IsEmptyDirectory checks if a directory is empty. ignoreENOENT if true, a non-exiting directory is ignored. pamnic on troubles

func MoveOrMerge

func MoveOrMerge(src, dest string, outConsumer func(string)) (err error)

func Mv

func Mv(src, dest string, outConsumer func(string)) (err error)

Mv moves a file or directory structure using system command. Mv uses -n for --n-clobber. Mv does not indicate if moive was aborted due to no-clobber. outConsumer can be nil but receiver command output if any. mv typically has no output.

func NewContextReader

func NewContextReader(ctx context.Context, reader io.Reader) io.Reader

NewContextReader instantiates ContextReader

func Stat

func Stat(path string) (fileInfo fs.FileInfo, err error)

func TestElemsX added in v0.4.26

func TestElemsX(t *testing.T)

func Walk

func Walk(root string, walkFn filepath.WalkFunc) (err error)

Walk pfs.Walk traverses a directory hierarchy following symlinks. Every entry in the hierarchy is provided exactly once to walkFn. To identify circular symlinks, the hierarchy is first completely scanned. golang has a similar built-in filepath.Walk that does not follow symlinks

Types

type ContextReader

type ContextReader struct {
	io.Reader
	// contains filtered or unexported fields
}

ContextReader reader terminated by context

func (*ContextReader) Read

func (cr *ContextReader) Read(p []byte) (n int, err error)

type DLEntry

type DLEntry struct {
	RelDir      string // directory name that may begin with '.'
	AbsDir      string // absolute directory name
	FqPath      string // fully qualified path to entry
	fs.DirEntry        // .Name() .IsDir() .Type() .Info()
	Info        fs.FileInfo
	Stat        *syscall.Stat_t
}

func GetEntry

func GetEntry(rel, abs string, entry fs.DirEntry, info fs.FileInfo, stat *syscall.Stat_t) (e *DLEntry)

type Directory

type Directory struct {
	Entry
	Children []FSEntry
}

Directory is a file system entry with children

func (*Directory) Walk

func (dir *Directory) Walk(path string, walkFunc filepath.WalkFunc) error

Walk traverses a built root

type DirectoryLister

type DirectoryLister struct {
	Path    string // may begin with ., may be .
	Abs     string
	Results chan *EntryResult
	// contains filtered or unexported fields
}

func NewDirStream

func NewDirStream(path string, chanSize int) (dir *DirectoryLister)

func (*DirectoryLister) Shutdown

func (dir *DirectoryLister) Shutdown()

type Entry

type Entry struct {
	Base        string // we can have entries with FileInfo nil, so base path must be stored
	os.FileInfo        // info.Name() has basename, os.FileInfo: interface
	Err         error  // a symlink may fail to resolve
}

Entry is a file system entry that can be part of directory, symlink or other

func (*Entry) SafeName

func (en *Entry) SafeName() string

SafeName gets filepath.Base() in a safe way

func (*Entry) Walk

func (en *Entry) Walk(path string, walkFunc filepath.WalkFunc) error

Walk traverses a built root

type EntryResult

type EntryResult struct {
	*DLEntry
	Err error
}

func GetErrorResult

func GetErrorResult(err error) (result *EntryResult)

type FSEntry

type FSEntry interface {
	SafeName() string
	IsDir() bool
	Walk(path string, walkFunc filepath.WalkFunc) error
}

FSEntry represnt a branch in a file system hierarchy FSEntry is implemented by Entry (file) or Directory or Root (walk entry point)

func NewDirectory

func NewDirectory(path string, entry *Entry, sym func(string)) FSEntry

NewDirectory instantiates FSEntry that can have children

func NewEntry

func NewEntry(path string, base string, sym func(string)) FSEntry

NewEntry returns Entry or Directory

type FileMode

type FileMode struct {
	fs.FileMode
}

func (FileMode) Ch

func (fm FileMode) Ch() (s string)

func (FileMode) Check

func (fm FileMode) Check() (str string)

Check returns hex string of unknown bits, empty string if no unknown bits

func (FileMode) Hex

func (fm FileMode) Hex() (s string)

func (FileMode) Hex8

func (fm FileMode) Hex8() (s string)

func (FileMode) Or

func (fm FileMode) Or() (s string)

func (FileMode) String

func (fm FileMode) String() (s string)

type IsDirectoryArg

type IsDirectoryArg byte
const (
	IsDirectoryNonExistentIsError IsDirectoryArg = 1 << iota
	IsDirectoryNotDirIsError
)

type Root

type Root struct {
	Path    string // path as provided
	Evaled  string // path after filepath.EvalSymlinks
	Err     error
	FSEntry // Directory or Entry
}

Root is a file system hierarchy

func NewRoot

func NewRoot(path string) (rt *Root, err error)

NewRoot allocates a root

func (*Root) Build

func (rt *Root) Build(sym func(string))

Build scans the file system for this root

func (*Root) Walk

func (rt *Root) Walk(walkFunc filepath.WalkFunc) error

Walk traverses the root

type Sha256

type Sha256 []byte

Sha256 contains sha-256 hash

func Sha256Context

func Sha256Context(ctx context.Context, filename string) (s2 Sha256, err error)

Sha256Context get sha256 of a file with context

func (Sha256) String

func (s2 Sha256) String() string

func (*Sha256) Valid

func (s2 *Sha256) Valid() bool

Valid determines if hash is present

type Tree

type Tree struct {
	List  []Root
	Index map[string]int // key: evaled path, value: index in RootList
}

Tree consists of one or more indexed roots, each root a subhierarchy of the file system

func NewTree

func NewTree() *Tree

NewTree allocates a Tree

func (*Tree) AddRoot

func (tree *Tree) AddRoot(path string) (symlinkTargets []string, err error)

AddRoot adds a new root

func (tree *Tree) ResolveSymlink(path string) (symlinkTargets []string, err error)

ResolveSymlink patches the tree for a symlink

func (*Tree) Walk

func (tree *Tree) Walk(walkFunc filepath.WalkFunc) error

Walk traverses the built tree

Jump to

Keyboard shortcuts

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