@@ -45,6 +45,7 @@ type naiveNotify struct {
4545 // the notify list. It might be better to store this in a tree
4646 // structure, so we can filter the list quickly.
4747 notifyList map [string ]bool
48+ ignore PathMatcher
4849
4950 isWatcherRecursive bool
5051 watcher * fsnotify.Watcher
@@ -113,6 +114,10 @@ func (d *naiveNotify) watchRecursively(dir string) error {
113114
114115 return filepath .WalkDir (dir , func (path string , info fs.DirEntry , err error ) error {
115116 if err != nil {
117+ if os .IsPermission (err ) && d .shouldIgnore (path ) {
118+ logrus .Debugf ("Ignoring path: %s" , path )
119+ return nil
120+ }
116121 return err
117122 }
118123
@@ -240,6 +245,11 @@ func (d *naiveNotify) shouldSkipDir(path string) bool {
240245 return false
241246 }
242247
248+ // If path is present in the ignore list then we should ignore it
249+ if d .shouldIgnore (path ) {
250+ return true
251+ }
252+
243253 // Suppose we're watching
244254 // /src/.tiltignore
245255 // but the .tiltignore file doesn't exist.
@@ -260,6 +270,26 @@ func (d *naiveNotify) shouldSkipDir(path string) bool {
260270 return true
261271}
262272
273+ func (d * naiveNotify ) shouldIgnore (path string ) bool {
274+ if d .ignore == nil {
275+ return false
276+ }
277+ matches , err := d .ignore .MatchesEntireDir (path )
278+ if err != nil {
279+ logrus .Debugf ("error checking ignored directory %q: %v" , path , err )
280+ return false
281+ }
282+ if matches {
283+ return true
284+ }
285+ matches , err = d .ignore .Matches (path )
286+ if err != nil {
287+ logrus .Debugf ("error checking ignored path %q: %v" , path , err )
288+ return false
289+ }
290+ return matches
291+ }
292+
263293func (d * naiveNotify ) add (path string ) error {
264294 err := d .watcher .Add (path )
265295 if err != nil {
@@ -270,7 +300,7 @@ func (d *naiveNotify) add(path string) error {
270300 return nil
271301}
272302
273- func newWatcher (paths []string ) (Notify , error ) {
303+ func newWatcher (paths []string , ignore PathMatcher ) (Notify , error ) {
274304 fsw , err := fsnotify .NewWatcher ()
275305 if err != nil {
276306 if strings .Contains (err .Error (), "too many open files" ) && runtime .GOOS == "linux" {
@@ -297,9 +327,9 @@ func newWatcher(paths []string) (Notify, error) {
297327 }
298328 notifyList [path ] = true
299329 }
300-
301330 wmw := & naiveNotify {
302331 notifyList : notifyList ,
332+ ignore : ignore ,
303333 watcher : fsw ,
304334 events : fsw .Events ,
305335 wrappedEvents : wrappedEvents ,
0 commit comments