Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/govim: add directory filtering to darwin file watcher #1038

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

leitzler
Copy link
Member

@leitzler leitzler commented Feb 9, 2021

The file watcher in darwin is recursive so adding and removing
directories to watch was no-ops. One issue with that was that the
filtering in cmd/govim/watcher.go that made sure files in directories
that starts with '.' or '_' wasn't watched didn't apply in darwin.

A consequence of that was that the test suite failed on darwin.

We now apply a simple filter to added paths and suppress events for
files outside those. Note that we do want to filter rather than
configuring the file watcher to be non-recursive to avoid #492.

The file watcher in darwin is recursive so adding and removing
directories to watch was no-ops. One issue with that was that the
filtering in cmd/govim/watcher.go that made sure files in directories
that starts with '.' or '_' wasn't watched didn't apply in darwin.

A consequence of that was that the test suite failed on darwin.

We now apply a simple filter to added paths and suppress events for
files outside those. Note that we do want to filter rather than
configuring the file watcher to be non-recursive to avoid #492.
@leitzler leitzler requested a review from myitcv February 9, 2021 22:37
Copy link
Member

@myitcv myitcv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple of questions/thoughts on how we could do this differently.


type fswatcher struct {
eventCh chan Event
es *fsevents.EventStream

// Darwin do recursive watching so we need to filter files in directories that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/do/does/


type fswatcher struct {
eventCh chan Event
es *fsevents.EventStream

// Darwin do recursive watching so we need to filter files in directories that
// wasn't explicitly added. Note that it is desirable to watch recursively to avoid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/wasn't/weren't/

// Darwin do recursive watching so we need to filter files in directories that
// wasn't explicitly added. Note that it is desirable to watch recursively to avoid
// a data race (#492).
watched map[string]bool // keyed by full path to directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per our offline chant, I'm not clear why this is necessary. On Darwin, given the watcher is recursive (which is a good thing) we don't need to do the filepath.Walk that adds recursive watchers.

Instead, we can simply check on the event callback whether the event is for a file we care about. i.e. ignore . and _ prefixed directories, as well as submodules.

It's not perfect of course and there are loads of potential FS races... but that's the nature of the beast 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants