MCPcopy
hub / github.com/docker/compose / newWatcher

Function newWatcher

pkg/watch/watcher_naive.go:273–311  ·  view source on GitHub ↗
(paths []string)

Source from the content-addressed store, hash-verified

271}
272
273func newWatcher(paths []string) (Notify, error) {
274 fsw, err := fsnotify.NewWatcher()
275 if err != nil {
276 if strings.Contains(err.Error(), "too many open files") && runtime.GOOS == "linux" {
277 return nil, fmt.Errorf("hit OS limits creating a watcher.\n" +
278 "Run 'sysctl fs.inotify.max_user_instances' to check your inotify limits.\n" +
279 "To raise them, run 'sudo sysctl fs.inotify.max_user_instances=1024'")
280 }
281 return nil, fmt.Errorf("creating file watcher: %w", err)
282 }
283 MaybeIncreaseBufferSize(fsw)
284
285 err = fsw.SetRecursive()
286 isWatcherRecursive := err == nil
287
288 wrappedEvents := make(chan FileEvent)
289 notifyList := make(map[string]bool, len(paths))
290 if isWatcherRecursive {
291 paths = pathutil.EncompassingPaths(paths)
292 }
293 for _, path := range paths {
294 path, err := filepath.Abs(path)
295 if err != nil {
296 return nil, fmt.Errorf("newWatcher: %w", err)
297 }
298 notifyList[path] = true
299 }
300
301 wmw := &naiveNotify{
302 notifyList: notifyList,
303 watcher: fsw,
304 events: fsw.Events,
305 wrappedEvents: wrappedEvents,
306 errors: fsw.Errors,
307 isWatcherRecursive: isWatcherRecursive,
308 }
309
310 return wmw, nil
311}
312
313var _ Notify = &naiveNotify{}
314

Callers 2

NewWatcherFunction · 0.70

Calls 2

ErrorMethod · 0.80
MaybeIncreaseBufferSizeFunction · 0.70

Tested by 1