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
Support additional event types #519
Comments
I looked around a bit, and:
As far as I can see, there are no events that are shared by all platforms. Need to think about how to best deal with this; #67 would be okay for some rare operations, but things like Read is available on quite a few platforms, and using a new .Sys() would be awkward. One way might be creating a new UnportableOp type:
This way it's always clear you're using unportable operations and can't accidentally do |
@arp242 What about leveraging GOOS build tags to limit which events can be used? With non-portable events guarded by build flags, if someone tried to build the following code for darwin, they'd get a compilation error: event := <-watcher.Events
if event.Has(inotify.Close) {
fmt.Println("File was closed")
} |
The problem with that is that many unportable events are supported by more than one platform. And even for events on one platform it's awkward to have fallbacks – I suppose you could make special handling for every platform, but that somewhat defeats the purpose of this library. Anyway, proposal at: #629 |
Overview of additional event types: inotify
fanotify
FreeBSD
OpenBSD
NetBSD
DragonflyBSD
FEN
Windows
fsevents
|
This adds the ability to only listen for some event types. If you're only interested in Created events and you're getting a lot of Write events then you're just wasting CPU cycles This also adds the ability listen on extra unportable event types; since this is so related I figured I might as well do both. Ideally we want to 1) make it very very obvious you're doing something unportable, and 2) make it reasonably easy "fallback" for platforms where this isn't supported. Unportable events start with "Unportable", which should document their unportabilitiness. Also add a new Supports(Op) method, which should make adding fallback logic relatively painless. For example, to use CloseWrite where supported, but falling back to Write when it's not: var op fsnotify.Op if w.Supports(fsnotify.UnportableCloseWrite) { op |= fsnotify.UnportableCloseWrite } else { op |= fsnotify.Create | fsnotify.Write } w.AddWith("/tmp", fsnotify.WithEvents(op)) And then you can deal with this in the write loop. There's a full example in cmd/fsnotify/closewrite.go All of this is unexported for now, until support for other platforms has been added. Updates #7 Updates #519
We only have Create, Remove, Rename, Write, and Chmod now, but many watchers support additional events. This has come up a few times:
Instead of creating a bunch of issues for every possible event, track them here.
All of this depends on #7; we don't want to spam people with e.g. Open and Close
events when they're not interested in them (which is most of the time), and some
events aren't supported on all platforms.
The text was updated successfully, but these errors were encountered: