filesys

package
v1.3.4-alpha7 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FsMonitorCreate = "create" // dir
	FsMonitorWrite  = "write"
	FsMonitorRename = "rename"
	FsMonitorRemove = "remove"
	FsMonitorChmod  = "chmod"
	FsMonitorChange = "change"
	FsMonitorTouch  = "touch"
	FsMonitorDelete = "delete"
)

Variables

View Source
var Exports = map[string]any{
	"Recursive": Recursive,

	"onReady":    withYaklangOnStart,
	"onStat":     withYaklangStat,
	"onFileStat": withYaklangFileStat,
	"onDirStat":  withYaklangDirStat,
	"dir":        WithDir,
}
View Source
var SkipAll = errors.New("skip all")
View Source
var SkipDir = errors.New("skip dir")

Functions

func Recursive

func Recursive(raw string, opts ...Option) error

Recursive recursively walk through the file system raw: the root path opts: options return: error

Example: ``` err := filesys.Recursive( //

"testdata",
filesys.dir(["cc", "dd"], filesys.onFileStat((name, info) => {})),

) ```

Types

type Config

type Config struct {
	RecursiveDirectory bool
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig() *Config

type DirStat added in v1.3.3

type DirStat func(string, fs.FileInfo) error

type Event

type Event struct {
	Path  string
	Op    string
	IsDir bool
}

type MonitorErrorsHandler func(error)

type EventSet

type EventSet struct {
	CreateEvents []Event
	DeleteEvents []Event
	ChangeEvents []Event
}

func CompareFileTree

func CompareFileTree(perv, current *FileNode) *EventSet

type FileNode

type FileNode struct {
	Info     os.FileInfo
	Path     string
	Children map[string]*FileNode
	Parent   *FileNode
	IsRoot   bool
}

func GetCurrentFileTree

func GetCurrentFileTree(path string) (*FileNode, error)

func (*FileNode) IsDir

func (n *FileNode) IsDir() bool

type FileStat added in v1.3.3

type FileStat func(string, fs.FileInfo) error

type FileSystem added in v1.3.3

type FileSystem interface {
	ReadFile(name string) ([]byte, error)

	Open(name string) (fs.File, error)

	// Stat returns a FileInfo describing the file.
	// If there is an error, it should be of type *PathError.
	Stat(name string) (fs.FileInfo, error)
	// RelStat(name string) (fs.FileInfo, error)
	// ReadDir reads the named directory
	// and returns a list of directory entries sorted by filename.
	ReadDir(name string) ([]fs.DirEntry, error)

	Join(elem ...string) string

	GetSeparators() rune
}

FileSystem defines the methods of an abstract filesystem.

func NewEmbedFS added in v1.3.3

func NewEmbedFS(fs embed.FS) FileSystem

type LocalFs added in v1.3.3

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

local filesystem

func NewLocalFs added in v1.3.3

func NewLocalFs() *LocalFs

func (*LocalFs) GetSeparators added in v1.3.3

func (f *LocalFs) GetSeparators() rune

func (*LocalFs) Join added in v1.3.3

func (f *LocalFs) Join(name ...string) string

func (*LocalFs) Open added in v1.3.3

func (f *LocalFs) Open(name string) (fs.File, error)

func (*LocalFs) ReadDir added in v1.3.3

func (f *LocalFs) ReadDir(dirname string) ([]fs.DirEntry, error)

func (*LocalFs) ReadFile

func (f *LocalFs) ReadFile(name string) ([]byte, error)

func (*LocalFs) Stat added in v1.3.3

func (f *LocalFs) Stat(name string) (fs.FileInfo, error)

type MonitorEventHandler

type MonitorEventHandler func(events *EventSet)

type Option

type Option func(*Config)

func WithDir

func WithDir(globDir string, opts ...Option) Option

func WithDirStat

func WithDirStat(f DirStat) Option

func WithDirWalkEnd

func WithDirWalkEnd(handle func(path string) error) Option

func WithEmbedFS

func WithEmbedFS(f embed.FS) Option

func WithFileStat

func WithFileStat(f FileStat) Option

func WithFileSystem

func WithFileSystem(f FileSystem) Option

func WithOnStart

func WithOnStart(f func(basename string, isDir bool) error) Option

func WithRecursiveDirectory added in v1.3.3

func WithRecursiveDirectory(b bool) Option

func WithStat

func WithStat(f func(isDir bool, pathname string, info os.FileInfo) error) Option

type VirtualFS added in v1.3.3

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

func NewVirtualFs added in v1.3.3

func NewVirtualFs() *VirtualFS

func (*VirtualFS) AddDir added in v1.3.3

func (vf *VirtualFS) AddDir(dirName string) *VirtualFile

func (*VirtualFS) AddFile added in v1.3.3

func (vs *VirtualFS) AddFile(name, content string)

func (*VirtualFS) GetLocalFSPath added in v1.3.3

func (vs *VirtualFS) GetLocalFSPath() string

func (*VirtualFS) GetSeparators added in v1.3.3

func (vs *VirtualFS) GetSeparators() rune

func (*VirtualFS) Join added in v1.3.3

func (vs *VirtualFS) Join(name ...string) string

func (*VirtualFS) Open added in v1.3.3

func (vs *VirtualFS) Open(name string) (fs.File, error)

func (*VirtualFS) ReadDir added in v1.3.3

func (vs *VirtualFS) ReadDir(name string) ([]fs.DirEntry, error)

func (*VirtualFS) ReadFile

func (vs *VirtualFS) ReadFile(name string) ([]byte, error)

func (*VirtualFS) RemoveFileOrDir added in v1.3.3

func (vs *VirtualFS) RemoveFileOrDir(name string) error

func (*VirtualFS) Stat added in v1.3.3

func (vs *VirtualFS) Stat(name string) (fs.FileInfo, error)

type VirtualFile added in v1.3.3

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

func NewVirtualFile added in v1.3.3

func NewVirtualFile(name string, content string) *VirtualFile

func NewVirtualFileDirectory added in v1.3.3

func NewVirtualFileDirectory(dirName string, dir *VirtualFS) *VirtualFile

func (*VirtualFile) Close added in v1.3.3

func (vf *VirtualFile) Close() error

func (*VirtualFile) Read added in v1.3.3

func (vf *VirtualFile) Read(p []byte) (int, error)

func (*VirtualFile) Stat added in v1.3.3

func (vf *VirtualFile) Stat() (fs.FileInfo, error)

type VirtualFileInfo added in v1.3.3

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

func NewVirtualFileInfo added in v1.3.3

func NewVirtualFileInfo(name string, size int64, isDir bool) *VirtualFileInfo

func (*VirtualFileInfo) Info added in v1.3.3

func (vi *VirtualFileInfo) Info() (fs.FileInfo, error)

func (*VirtualFileInfo) IsDir added in v1.3.3

func (vi *VirtualFileInfo) IsDir() bool

func (*VirtualFileInfo) ModTime added in v1.3.3

func (vi *VirtualFileInfo) ModTime() time.Time

func (*VirtualFileInfo) Mode added in v1.3.3

func (vi *VirtualFileInfo) Mode() os.FileMode

func (*VirtualFileInfo) Name added in v1.3.3

func (vi *VirtualFileInfo) Name() string

func (*VirtualFileInfo) Size added in v1.3.3

func (vi *VirtualFileInfo) Size() int64

func (*VirtualFileInfo) Sys added in v1.3.3

func (vi *VirtualFileInfo) Sys() any

func (*VirtualFileInfo) Type added in v1.3.3

func (vi *VirtualFileInfo) Type() fs.FileMode

type YakFileMonitor

type YakFileMonitor struct {
	Events          chan *EventSet
	RecursiveFinish chan struct{} // recursive finish

	FileTreeMutex sync.Mutex
	FileTree      *FileNode

	WatchPatch string

	Ctx        context.Context
	CancelFunc context.CancelFunc
}

func WatchPath

func WatchPath(ctx context.Context, path string, eventHandler MonitorEventHandler) (*YakFileMonitor, error)

func (*YakFileMonitor) SetFileTree

func (m *YakFileMonitor) SetFileTree(fileTree *FileNode)

func (*YakFileMonitor) UpdateFileTree

func (m *YakFileMonitor) UpdateFileTree() error

Jump to

Keyboard shortcuts

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