aboutsummaryrefslogtreecommitdiff
path: root/internal/watcher/watch.go
blob: 95146cebc687d9b1c7e9b5c8494e0556ed3a29c7 (plain)
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
package watcher

import (
	"io/fs"
	"path/filepath"

	"github.com/fsnotify/fsnotify"
)

// watchTree recursively watches root and all of its subdirectories.
func watchTree(
	w *fsnotify.Watcher,
	root string,
) error {
	return filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
		if err != nil {
			return err
		}

		if !d.IsDir() {
			return nil
		}

		return w.Add(path)
	})
}