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

Support filtering events, add unsupported events #629

Merged
merged 1 commit into from
May 1, 2024
Merged

Support filtering events, add unsupported events #629

merged 1 commit into from
May 1, 2024

Commits on May 1, 2024

  1. inotify: support filtering events, add unsupported events

    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
    arp242 committed May 1, 2024
    Configuration menu
    Copy the full SHA
    0a0b082 View commit details
    Browse the repository at this point in the history