()
| 55 | } |
| 56 | |
| 57 | func (d *naiveNotify) Start() error { |
| 58 | if len(d.notifyList) == 0 { |
| 59 | return nil |
| 60 | } |
| 61 | |
| 62 | pathsToWatch := []string{} |
| 63 | for path := range d.notifyList { |
| 64 | pathsToWatch = append(pathsToWatch, path) |
| 65 | } |
| 66 | |
| 67 | pathsToWatch, err := greatestExistingAncestors(pathsToWatch) |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | if d.isWatcherRecursive { |
| 72 | pathsToWatch = pathutil.EncompassingPaths(pathsToWatch) |
| 73 | } |
| 74 | |
| 75 | for _, name := range pathsToWatch { |
| 76 | fi, err := os.Stat(name) |
| 77 | if err != nil && !os.IsNotExist(err) { |
| 78 | return fmt.Errorf("notify.Add(%q): %w", name, err) |
| 79 | } |
| 80 | |
| 81 | // if it's a file that doesn't exist, |
| 82 | // we should have caught that above, let's just skip it. |
| 83 | if os.IsNotExist(err) { |
| 84 | continue |
| 85 | } |
| 86 | |
| 87 | if fi.IsDir() { |
| 88 | err = d.watchRecursively(name) |
| 89 | if err != nil { |
| 90 | return fmt.Errorf("notify.Add(%q): %w", name, err) |
| 91 | } |
| 92 | } else { |
| 93 | err = d.add(filepath.Dir(name)) |
| 94 | if err != nil { |
| 95 | return fmt.Errorf("notify.Add(%q): %w", filepath.Dir(name), err) |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | go d.loop() |
| 101 | |
| 102 | return nil |
| 103 | } |
| 104 | |
| 105 | func (d *naiveNotify) watchRecursively(dir string) error { |
| 106 | if d.isWatcherRecursive { |
nothing calls this directly
no test coverage detected