Documentation
¶
Overview ¶
Package filewatcher is used to handle watching for file changes inside the monorepo
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCookieTimeout is returned when we did not see our cookie file within the given time constraints ErrCookieTimeout = errors.New("timed out waiting for cookie") // ErrCookieWatchingClosed is returned when the underlying filewatching has been closed. ErrCookieWatchingClosed = errors.New("filewatching has closed, cannot watch cookies") )
var ( // ErrFilewatchingClosed is returned when filewatching has been closed ErrFilewatchingClosed = errors.New("Close() has already been called for filewatching") // ErrFailedToStart is returned when filewatching fails to start up ErrFailedToStart = errors.New("filewatching failed to start") )
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface { AddRoot(root turbopath.AbsoluteSystemPath, excludePatterns ...string) error Events() <-chan Event Errors() <-chan error Close() error Start() error }
Backend is the interface that describes what an underlying filesystem watching backend must provide.
func GetPlatformSpecificBackend ¶
GetPlatformSpecificBackend returns a filewatching backend appropriate for the OS we are running on.
type CookieJar ¶
type CookieJar struct {
// contains filtered or unexported fields
}
CookieJar is used for tracking roundtrips through the filesystem watching API
func NewCookieJar ¶
func NewCookieJar(cookieDir turbopath.AbsoluteSystemPath, timeout time.Duration) (*CookieJar, error)
NewCookieJar returns a new instance of a CookieJar. There should only ever be a single instance live per cookieDir, since they expect to have full control over that directory.
func (*CookieJar) OnFileWatchClosed ¶
func (cj *CookieJar) OnFileWatchClosed()
OnFileWatchClosed handles the case where filewatching had to close for some reason We send an error to all of our cookies and stop accepting new ones.
func (*CookieJar) OnFileWatchError ¶
OnFileWatchError handles when filewatching has encountered an error. In the error case, we remove all cookies and send them errors. We remain available for later cookies.
func (*CookieJar) OnFileWatchEvent ¶
OnFileWatchEvent determines if the specified event is relevant for cookie watching and notifies the appropriate cookie if so.
func (*CookieJar) WaitForCookie ¶
WaitForCookie touches a unique file, then waits for it to show up in filesystem notifications. This provides a theoretical bound on filesystem operations, although it's possible that underlying filewatch mechanisms don't respect this ordering.
type CookieWaiter ¶
type CookieWaiter interface {
WaitForCookie() error
}
CookieWaiter is the interface used by clients that need to wait for a roundtrip through the filewatching API.
type Event ¶
type Event struct { Path turbopath.AbsoluteSystemPath EventType FileEvent }
Event is the backend-independent information about a file change
type FileEvent ¶
type FileEvent int
FileEvent is an enum covering the kinds of things that can happen to files that we might be interested in
const ( // FileAdded - this is a new file FileAdded FileEvent = iota + 1 // FileDeleted - this file has been removed FileDeleted // FileModified - this file has been changed in some way FileModified // FileRenamed - a file's name has changed FileRenamed // FileOther - some other backend-specific event has happened FileOther )
type FileWatchClient ¶
type FileWatchClient interface { OnFileWatchEvent(ev Event) OnFileWatchError(err error) OnFileWatchClosed() }
FileWatchClient defines the callbacks used by the file watching loop. All methods are called from the same goroutine so they: 1) do not need synchronization 2) should minimize the work they are doing when called, if possible
type FileWatcher ¶
type FileWatcher struct {
// contains filtered or unexported fields
}
FileWatcher handles watching all of the files in the monorepo. We currently ignore .git and top-level node_modules. We can revisit if necessary.
func New ¶
func New(logger hclog.Logger, repoRoot turbopath.AbsoluteSystemPath, backend Backend) *FileWatcher
New returns a new FileWatcher instance
func (*FileWatcher) AddClient ¶
func (fw *FileWatcher) AddClient(client FileWatchClient)
AddClient registers a client for filesystem events
func (*FileWatcher) AddRoot ¶
func (fw *FileWatcher) AddRoot(root turbopath.AbsoluteSystemPath, excludePatterns ...string) error
AddRoot registers the root a filesystem hierarchy to be watched for changes. Events are *not* fired for existing files when AddRoot is called, only for subsequent changes. NOTE: if it appears helpful, we could change this behavior so that we provide a stream of initial events.
func (*FileWatcher) Start ¶
func (fw *FileWatcher) Start() error
Start recursively adds all directories from the repo root, redacts the excluded ones, then fires off a goroutine to respond to filesystem events