From 60078b8452867c9ab40c9623ef63169bdb090c83 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Thu, 9 Mar 2023 22:26:03 +0100 Subject: fswatcher: fix bsd support Fix the following error when running maildir on freebsd: could not create file system watcher: Unsupported OS: freebsd Do not register based on os type. Register based on supported API. Rename linux -> inotify and darwin -> fsevents. Only build fsevents on darwin, and inotify on all other platforms. Fixes: a0935a3de0ce ("worker/lib: implement an fswatcher interface") Reported-by: Jens Grassel Signed-off-by: Robin Jarry Tested-by: Jens Grassel --- worker/handlers/register.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'worker/handlers/register.go') diff --git a/worker/handlers/register.go b/worker/handlers/register.go index c94a256e..4123665f 100644 --- a/worker/handlers/register.go +++ b/worker/handlers/register.go @@ -29,15 +29,15 @@ func GetHandlerForScheme(scheme string, worker *types.Worker) (types.Backend, er type WatcherFactoryFunc func() (types.FSWatcher, error) -var watcherFactories map[string]WatcherFactoryFunc = make(map[string]WatcherFactoryFunc) +var watcherFactory WatcherFactoryFunc -func RegisterWatcherFactory(os string, fn WatcherFactoryFunc) { - watcherFactories[os] = fn +func RegisterWatcherFactory(fn WatcherFactoryFunc) { + watcherFactory = fn } func NewWatcher() (types.FSWatcher, error) { - if fn, ok := watcherFactories[runtime.GOOS]; ok { - return fn() + if watcherFactory == nil { + return nil, fmt.Errorf("Unsupported OS: %s", runtime.GOOS) } - return nil, fmt.Errorf("Unsupported OS: %s", runtime.GOOS) + return watcherFactory() } -- cgit