files

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownFile = errors.New("unknown file name")
	ErrFileTracked = errors.New("file already tracked")
)

Functions

This section is empty.

Types

type Event

type Event struct {
	Name string
	Op   fsnotify.Op
}

func (Event) Type

func (e Event) Type() EventType

type EventType

type EventType string
const (
	EventTypeUnknown EventType = "unknown"
	EventTypeChmod   EventType = "chmod"
	EventTypeCreate  EventType = "create"
	EventTypeRemove  EventType = "remove"
	EventTypeRename  EventType = "rename"
	EventTypeWrite   EventType = "write"
)

type FileInfo

type FileInfo struct {
	fs.FileInfo

	FileType      FileType
	WasDeleted    bool // This is to track the deletion of initial files. New files will be removed from the map with Delete()
	Writes        int64
	PreSwapWrites int64 // Writes that occurred before editor swaps (not counted in final total)
	PendingSwap   bool  // True if file has a pending delete that might be part of an editor swap
}

func (FileInfo) IsInitial

func (f FileInfo) IsInitial() bool

type FileMap

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

func NewFileMap

func NewFileMap() *FileMap

func (*FileMap) AddFile

func (f *FileMap) AddFile(path string, info FileInfo) error

func (*FileMap) AddNewPath

func (f *FileMap) AddNewPath(path string) error

AddNewPath will stat the given path and add it to the map if it is not already known. This should not be used for initial files. Calling this with a known path will return ErrFileTracked.

func (*FileMap) AddSwapWrite

func (f *FileMap) AddSwapWrite(path string) error

AddSwapWrite records a write from an editor swap (delete+create pair). It also clears any writes that occurred just before the swap to avoid double-counting.

func (*FileMap) AddWrite

func (f *FileMap) AddWrite(path string) error

func (*FileMap) Delete

func (f *FileMap) Delete(path string) error

func (*FileMap) DeletedFiles

func (f *FileMap) DeletedFiles() []string

func (*FileMap) FilePathsByBase

func (f *FileMap) FilePathsByBase(name string) []string

func (*FileMap) FilesCreated

func (f *FileMap) FilesCreated() int64

func (*FileMap) FilesDeleted

func (f *FileMap) FilesDeleted() int64

func (*FileMap) Get

func (f *FileMap) Get(path string) (FileInfo, error)

func (*FileMap) Has

func (f *FileMap) Has(path string) bool

func (*FileMap) IsDir

func (f *FileMap) IsDir(path string) bool

func (*FileMap) IsInitial

func (f *FileMap) IsInitial(path string) bool

func (*FileMap) MarkPendingSwap

func (f *FileMap) MarkPendingSwap(path string)

MarkPendingSwap marks a file as potentially being swapped by an editor. This prevents writes from being counted until we know if a swap occurred.

func (*FileMap) NewFiles

func (f *FileMap) NewFiles() []string

func (*FileMap) WrittenFiles

func (f *FileMap) WrittenFiles() map[string]int64

type FileType

type FileType string
const (
	FileTypeInitial FileType = "initial"
	FileTypeNew     FileType = "new"
)

type Monitor

type Monitor struct {
	Events chan Event
	// contains filtered or unexported fields
}

func NewMonitor

func NewMonitor(opts *MonitorOpts) (*Monitor, error)

func (*Monitor) Close

func (m *Monitor) Close()

func (*Monitor) FileMap

func (m *Monitor) FileMap() *FileMap

func (*Monitor) Run

func (m *Monitor) Run(ctx context.Context)

func (*Monitor) Stats

func (m *Monitor) Stats(final bool) *Stats

func (*Monitor) WatchDirRecursive

func (m *Monitor) WatchDirRecursive(path string, initial bool) error

func (*Monitor) WatchFile

func (m *Monitor) WatchFile(path string, initial bool) error

type MonitorOpts

type MonitorOpts struct {
	RootPath    string
	WatchRoot   bool
	TrackWrites bool
}

func (*MonitorOpts) OK

func (m *MonitorOpts) OK() error

type Stats

type Stats struct {
	NumFilesCreated int64
	NumFilesDeleted int64
	NewFiles        []string
	DeletedFiles    []string
	WrittenFiles    map[string]int64
}

Jump to

Keyboard shortcuts

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