File: fsmonitor.go

package info (click to toggle)
incus 6.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,392 kB
  • sloc: sh: 16,313; ansic: 3,121; python: 457; makefile: 337; ruby: 51; sql: 50; lisp: 6
file content (32 lines) | stat: -rw-r--r-- 950 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package fsmonitor

import (
	"github.com/lxc/incus/v6/internal/server/fsmonitor/drivers"
	"github.com/lxc/incus/v6/shared/logger"
)

type fsMonitor struct {
	driver drivers.Driver
	logger logger.Logger
}

// PrefixPath returns the prefix path.
func (fs *fsMonitor) PrefixPath() string {
	return fs.driver.PrefixPath()
}

// Watch creates a watch for a path which may or may not yet exist. If the provided path gets an
// inotify event, f() is called.
// Note: If f() returns false, the watch is removed.
func (fs *fsMonitor) Watch(path string, identifier string, f func(path string, event string) bool) error {
	fs.logger.Info("Watching path", logger.Ctx{"path": path})

	return fs.driver.Watch(path, identifier, f)
}

// Unwatch removes the given path from the watchlist.
func (fs *fsMonitor) Unwatch(path string, identifier string) error {
	fs.logger.Info("Unwatching path", logger.Ctx{"path": path})

	return fs.driver.Unwatch(path, identifier)
}