watch

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Watches a directory recursively, translating file system events into our internal Op structure.

File events are complicated! Here are some helpful links: https://fsnotify.org/ http://man7.org/linux/man-pages/man7/inotify.7.html

Index

Constants

View Source
const CheckLimitKey = "WM_CHECK_LIMIT"
View Source
const MAX_COALESCE = 10

We put a cap on how many sequential events to coalesce for use-cases like log files where we see continuous data for a long time.

Variables

This section is empty.

Functions

func DefaultMatcher

func DefaultMatcher() *ospath.Matcher

The default matcher of a watcher. Just ignores .git directories.

func LimitChecksEnabled

func LimitChecksEnabled() bool

func NewWatcher

func NewWatcher() (wmNotify, error)

func SetLimitChecksEnabled

func SetLimitChecksEnabled(enabled bool)

Allows limit checks to be disabled for testing.

Types

type RecipeTagProvider

type RecipeTagProvider func() data.RecipeWTag

func NewRecipeTagProvider

func NewRecipeTagProvider(tag data.RecipeWTag) RecipeTagProvider

type WatchErrEvent

type WatchErrEvent struct {
	Err error
}

There was an error.

type WatchEvent

type WatchEvent interface {
	// contains filtered or unexported methods
}

type WatchOpsEvent

type WatchOpsEvent struct {
	SnapID data.SnapshotID
	Ops    []data.Op
}

New ops have been created

func ChangesSinceModTimeToOpsEvent

func ChangesSinceModTimeToOpsEvent(path string, db dbint.DB2, previous data.SnapshotID, owner data.UserID, minMtime time.Time) (WatchOpsEvent, error)

Crawls a directory for modifications since the given time, and generates temp write ops for everything in it.

func DirectoryToOpsEvent

func DirectoryToOpsEvent(path string, db dbint.DB2, matcher *ospath.Matcher,
	previous data.SnapshotID, owner data.UserID, tag data.RecipeWTag) (WatchOpsEvent, error)

Crawls a directory, and generates write ops for everything in it.

func (WatchOpsEvent) IsEmpty

func (e WatchOpsEvent) IsEmpty() bool

type WatchSyncEvent

type WatchSyncEvent struct {
	Token string
}

Somebody requested an fsync.

type WorkspaceWatcher

type WorkspaceWatcher struct {
	Events chan WatchEvent
	// contains filtered or unexported fields
}

Watches a directory of files and emits Ops for each change.

func NewWorkspaceWatcher

func NewWorkspaceWatcher(path string, db dbint.DB2, matcher *ospath.Matcher, owner data.UserID, tag data.RecipeWTag, tmp *temp.TempDir) (*WorkspaceWatcher, error)

Watches a directory. Does not generate write ops for existing contents.

func NewWorkspaceWatcherAndSync

func NewWorkspaceWatcherAndSync(path string, db dbint.DB2, previous data.SnapshotID, matcher *ospath.Matcher, owner data.UserID,
	tagFn RecipeTagProvider, tmp *temp.TempDir) (*WorkspaceWatcher, error)

Watches a directory.

Generates write ops for any existing contents of the directory that aren't in the snapshot, and remove ops for any contents of the snapshot that aren't in the directory.

The use of RecipeTagProvider is a major hack so that we can assign a Temp tag recipe to the initial ops. I wish we had a better way to do this but this is good enough for now.

func NewWorkspaceWatcherWithLimit

func NewWorkspaceWatcherWithLimit(path string, db dbint.DB2, matcher *ospath.Matcher, owner data.UserID, tag data.RecipeWTag, tmp *temp.TempDir, maxFiles int) (*WorkspaceWatcher, error)

func (*WorkspaceWatcher) Close

func (ww *WorkspaceWatcher) Close() error

func (*WorkspaceWatcher) FSync

func (ww *WorkspaceWatcher) FSync(ctx context.Context, token string) error

Wait for WorkspaceWatcher to catch up We accomplish this by writing to a file in a sync directory and waiting to notice. Sends a SyncOp on the ops channel with the given token. Cf. https://facebook.github.io/watchman/docs/cookies.html TODO(dbentley): what if they end up on different filesystems?

func (*WorkspaceWatcher) Matcher

func (ww *WorkspaceWatcher) Matcher() *ospath.Matcher

func (*WorkspaceWatcher) NotifyOnChange

func (ww *WorkspaceWatcher) NotifyOnChange(path string, c chan struct{})

func (*WorkspaceWatcher) Root

func (ww *WorkspaceWatcher) Root() string

Jump to

Keyboard shortcuts

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