pfs

package module
v0.4.21 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: ISC Imports: 24 Imported by: 3

Documentation

Overview

Package pfs provides file-system related functions

Package pfs provides file-system related functions

Index

Constants

View Source
const (
	Create fsnotify.Op = 1 << iota
	Write
	Remove
	Rename
	Chmod
)
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
)
View Source
const WatchOpAll fsnotify.Op = 0 // Create|Write|Remove|Rename|Chmod

Variables

View Source
var E = 17

Functions

func AbsEval

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

AbsEval makes path absolute and resolves symlinks

func AppDir

func AppDir(appName string) (directory string)

AppDir gets an app-specific file system directory

func Dirs

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

Dirs retrieves absolute paths to all directories, while following symlinks, from initial dir argument

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)

fileInfo: does exist, nil: does not exist

func GetModeBitValues

func GetModeBitValues() (s string)

func IsDirectory

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

func IsEmptyDirectory

func IsEmptyDirectory(path string) (isEmpty bool)

func MoveOrMerge

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

func Mv

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

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 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 AppDirectory

type AppDirectory struct {
	App string
}

func NewAppDir

func NewAppDir(appName string) (appd *AppDirectory)

NewAppDir returns an object providing an app-specific file system location with defered directory creation

func (*AppDirectory) Directory

func (appd *AppDirectory) Directory() (directory string)

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 Op

type Op fsnotify.Op

func (Op) String

func (op Op) String() (s string)

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

type Watch

type Watch struct {
	Now time.Time
	ID  int64
	// contains filtered or unexported fields
}

func NewWatch

func NewWatch(directory string, filter fsnotify.Op, ctx context.Context) (watch *Watch)

NewWatch produces events from a file-system entry and its child directories. WatchEvents must be listened for on the .Events() channel until it closes. Events that can be listened for are WatchOpAll (default: 0) Create Write Remove Rename Chmod. errors must be listened for on the .Errors() channel until it closes. Close the watcher by canceling the context or invoking .Shutdown().

220315 github.com/fsnotify/fsnotify v1.4.9 does not support macOS 220315 use the old github.com/fsnotify/fsevents v0.1.1

func (*Watch) Errors

func (wa *Watch) Errors() (errCh <-chan error)

func (*Watch) Events

func (wa *Watch) Events() (events <-chan *WatchEvent)

Events returns a receiver channel for pfs.WatchEvent

func (*Watch) Shutdown

func (wa *Watch) Shutdown()

type WatchEvent

type WatchEvent struct {
	At        time.Time // ns resolution
	ID        uuid.UUID // unique event identifier [16]byte
	BaseName  string    // filename.ext
	AbsName   string    // /absolute-path/filename.ext
	CleanName string    // may-have-symlinks/filename.ext
	Op        string    // CREATE|REMOVE|WRITE|RENAME|CHMOD

}

func (WatchEvent) String

func (we WatchEvent) String() string

Jump to

Keyboard shortcuts

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