Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions regolith/watcher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package regolith

import (
"os"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -85,12 +86,26 @@ func (d *DirWatcher) watch() error {
}
d.watcher = watcher
for _, root := range d.roots {
// We have to manually signal to fsnotify that it should recursively watch this
// path by using "/..." or "\...".
recursiveRoot := filepath.Join(root, "...")
if err := d.watcher.Add(recursiveRoot); err != nil {
// Add the root directory itself first
if err := d.watcher.Add(root); err != nil {
return burrito.WrapErrorf(err, "Could not start watching `%s`", root)
}

// Manually walk and add subdirectories for macOS compatibility
err := filepath.WalkDir(root, func(path string, info os.DirEntry, err error) error {
if err != nil {
return err
}
if info.IsDir() && path != root {
if err := d.watcher.Add(path); err != nil {
return err
}
}
return nil
})
if err != nil {
return burrito.WrapErrorf(err, "Could not recursively watch `%s`", root)
}
}
return nil
}
Expand Down