observer

package
v0.0.0-...-841f565 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeNotification

type ChangeNotification struct {
	Files   []*fs.File
	Matched map[string]*FileMatchCache
}

ChangeNotification represents a change in the file system and any matches that were registered

type FileFilter

type FileFilter func(file string) bool

FileFilter should return true if the file should be retained

type FileMatchCache

type FileMatchCache struct {
	Matcher  *pattern.Matcher
	Files    sync.Map
	Hash     hash.Hash
	PrevHash hash.Hash
}

FileMatchCache uses an pattern.Matcher to capture and cache a list of files passing through the observers.FileSystemStream

func (*FileMatchCache) Changed

func (f *FileMatchCache) Changed() bool

Changed compares the byte values of Hash and PrevHash to detect changes

func (*FileMatchCache) ComputeHash

func (f *FileMatchCache) ComputeHash()

ComputeHash generates a sha256 hash of the cached files

func (FileMatchCache) Copy

func (f FileMatchCache) Copy() *FileMatchCache

Copy returns a deep copy of this FileMatchCache

func (*FileMatchCache) FilesList

func (f *FileMatchCache) FilesList() (fileList []*fs.File)

FilesList returns the file list as a slice of fs.Files

func (*FileMatchCache) FilesStringList

func (f *FileMatchCache) FilesStringList(filter FileFilter) (fileList []string)

FilesStringList returns the file list as a slice of fs.Files

func (*FileMatchCache) GzipArchive

func (f *FileMatchCache) GzipArchive(prefix string, dest io.Writer, filter FileFilter, inject fs.TarInjectorFunc) error

GzipArchive writes all cached files to a dest io.Writer Allows passing a prefix to trim from file names and a tar archive injector

func (*FileMatchCache) Len

func (f *FileMatchCache) Len() int

Len returns the length of the Files sync.Map

func (*FileMatchCache) SortedFiles

func (f *FileMatchCache) SortedFiles() []*fs.File

SortedFiles returns a sorted list of files by name

func (*FileMatchCache) SortedFilesStringList

func (f *FileMatchCache) SortedFilesStringList() []string

SortedFilesStringList returns a sorted list of files by name

type Observer

type Observer struct {
	Root             string
	Ignore           []string
	Logger           logz.FieldLogger
	GitIgnoreMatcher gitignore.Matcher
	FileSystemStream rxgo.Observable

	WaitForInitialScan chan bool

	WatchmanClient *watchman.Client
	// contains filtered or unexported fields
}

Observer watches the filesystem for changes and notifies interested processes

func NewObserver

func NewObserver(
	nativeMode, watch bool,
	root string,
	ignore []string,
	gitIgnoreMatcher gitignore.Matcher,
	logger logz.FieldLogger,
	watchmanClient *watchman.Client,
) *Observer

NewObserver returns a deferred file system observer

func NewObserverWithoutIndexing

func NewObserverWithoutIndexing(
	nativeMode, watch bool,
	root string,
	ignore []string,
	gitIgnoreMatcher gitignore.Matcher,
	logger logz.FieldLogger,
	watchmanClient *watchman.Client,
) *Observer

NewObserverWithoutIndexing returns a deferred file system observer without the indexing capabilities

func (*Observer) AddFileMatcher

func (o *Observer) AddFileMatcher(key string, matcher *pattern.Matcher) error

AddFileMatcher adds a fileMatcher which is used to group files observed files

func (*Observer) GetMatchCache

func (o *Observer) GetMatchCache(key string) (*FileMatchCache, bool)

GetMatchCache returns a match cache by its registered key

func (*Observer) Reindex

func (o *Observer) Reindex() (*ChangeNotification, error)

Reindex executes a get on the FileSystemSteam to trigger file system indexing this function automatically cancels observation of the file system

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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