package filenotify

import "github.com/gohugoio/hugo/watcher/filenotify"

Package filenotify provides a mechanism for watching file(s) for changes. Generally leans on fsnotify, but provides a poll-based notifier which fsnotify does not support. These are wrapped up in a common interface so that either can be used interchangeably in your code.

This package is adapted from https://github.com/moby/moby/tree/master/pkg/filenotify, Apache-2.0 License. Hopefully this can be replaced with an external package sometime in the future, see https://github.com/fsnotify/fsnotify/issues/9

Index

Types

type FileWatcher

type FileWatcher interface {
	Events() <-chan fsnotify.Event
	Errors() <-chan error
	Add(name string) error
	Remove(name string) error
	Close() error
}

FileWatcher is an interface for implementing file notification watchers

func New

func New(interval time.Duration) (FileWatcher, error)

New tries to use an fs-event watcher, and falls back to the poller if there is an error

func NewEventWatcher

func NewEventWatcher() (FileWatcher, error)

NewEventWatcher returns an fs-event based file watcher

func NewPollingWatcher

func NewPollingWatcher(interval time.Duration) FileWatcher

NewPollingWatcher returns a poll-based file watcher

Source Files

filenotify.go fsnotify.go poller.go

Version
v0.144.2 (latest)
Published
Feb 19, 2025
Platform
linux/amd64
Imports
8 packages
Last checked
13 hours ago

Tools for package owners.