Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Watcher ¶
type Watcher struct { // Events is used to signal changes to any of the tracked files. It is // guaranteed that Event.Name will always match one of the file paths // passed in trackedFiles to the constructor. This channel is unbuffered // and must be read by the consumer to avoid deadlocks. Events chan Event // Errors reports any errors which may occur while watching. This channel // is unbuffered and must be read by the consumer to avoid deadlocks. Errors chan error // contains filtered or unexported fields }
Watcher is a wrapper around fsnotify.Watcher which can track non-existing files and emit creation events for them. All files which are supposed to be tracked need to passed to the New constructor.
- If the file already exists, the watcher will emit write, chmod, remove and rename events for the file (same as fsnotify).
- If the file does not yet exist, then the Watcher makes sure to watch the appropriate parent folder instead. Once the file is created, this watcher will emit a creation event for the tracked file and enter case 1.
- If the file already exists, but is removed, then a remove event is emitted and we enter case 2.
Special care has to be taken around symlinks. Support for symlink is limited, but it supports the following cases in order to support Kubernetes volume mounts:
- If the tracked file is a symlink, then the watcher will emit write, chmod, remove and rename events for the *target* of the symlink.
- If a tracked file is a symlink and the symlink target is removed, then the remove event is emitted and the watcher tries to re-resolve the symlink target. If the new target exists, a creation event is emitted and we enter case 1). If the new target does not exist, an error is emitted and the path will not be watched anymore.
Most notably, if a tracked file is a symlink, any update of the symlink itself does not emit an event. Only if the target of the symlink observes an event is the symlink re-evaluated.
Click to show internal directories.
Click to hide internal directories.