NewFSNotify creates a new file system watcher that watches parent directories instead of individual files for more reliable event detection.
()
| 48 | // NewFSNotify creates a new file system watcher that watches parent directories |
| 49 | // instead of individual files for more reliable event detection. |
| 50 | func NewFSNotify() (Watcher, error) { |
| 51 | w, err := fsnotify.NewWatcher() |
| 52 | if err != nil { |
| 53 | return nil, xerrors.Errorf("create fsnotify watcher: %w", err) |
| 54 | } |
| 55 | return &fsnotifyWatcher{ |
| 56 | Watcher: w, |
| 57 | done: make(chan struct{}), |
| 58 | watchedFiles: make(map[string]bool), |
| 59 | watchedDirs: make(map[string]int), |
| 60 | }, nil |
| 61 | } |
| 62 | |
| 63 | func (f *fsnotifyWatcher) Add(file string) error { |
| 64 | absPath, err := filepath.Abs(file) |