Coder Social home page Coder Social logo

Built-in event filtering of Ops about fsnotify HOT 6 OPEN

fsnotify avatar fsnotify commented on September 27, 2024
Built-in event filtering of Ops

from fsnotify.

Comments (6)

nathany avatar nathany commented on September 27, 2024

My current suggestion is to set the Op filter globally at the Watcher level instead of for each Watch added. Preferably in such a way that it cannot be changed later. Perhaps something like:

watcher, err := fsnotify.NewWatcher(fsnotify.Create|fsnotify.Write)
  • The filter can be passed to each adapter to have the OS filter out events the best it can.
  • A final user-space filter can catch any outliers without requiring the significant amount of bookkeeping of the previous implementation.
  • For the same reasons that directory watches are easier to manage, a user-space recursive watcher will be simpler to implement, whether included in fsnotify or externally.

from fsnotify.

nightlyone avatar nightlyone commented on September 27, 2024

I like your proposal of doing the Ops filtering on creation of the watcher.

One usually creates such a watcher with a purpose in mind and the events being delivered are usually suitable for this purpose for the lifetime of the watcher. And after all this is just an optimization. One can always choose a broader scope in order to be sure.

So maybe an additional simple creation function like NewGreedyWatcher might be useful OR an additional complex creation function like NewFilteredWatcher. One of those is meant to be without arguments.

from fsnotify.

tsuna avatar tsuna commented on September 27, 2024

The current code of Add() contains:

    const agnosticEvents = unix.IN_MOVED_TO | unix.IN_MOVED_FROM |
        unix.IN_CREATE | unix.IN_ATTRIB | unix.IN_MODIFY |
        unix.IN_MOVE_SELF | unix.IN_DELETE | unix.IN_DELETE_SELF

    var flags uint32 = agnosticEvents

So basically the flags are hard-coded to the ones above. Would there be any opposition to adding another API, like:

func (w *Watcher) Add(name string) error {
    return w.AddWithFlags(name, agnosticEvents)
}

func (w *Watcher) AddWithFlags(name string, flags uint32) error {
    // mostly the same code as the current Add() but use flags passed in argument

I need to ignore IN_DELETE_SELF because it's misleading in my case (and causes correctness issues in my code), I only care about IN_DELETE.

from fsnotify.

nathany avatar nathany commented on September 27, 2024

@tsuna The problem with adding a new API like that is that the flags differ from platform to platform. That's partly why I'd like to split out inotify #173 so it can be used independently in special Linux-only cases.

This issue is tracking a more general solution, which may be a ways off yet.

from fsnotify.

tsuna avatar tsuna commented on September 27, 2024

I hear you, although I personally don't think it's a big problem that the flags differ across the platforms, since this API would just take a uint32 and what values make sense for this API could be platform specific. So this would be a more advanced API for those needing the extra control.

Now when I reviewed the open issues I missed #173, that's obviously a more elegant solution, and at this rate between this bug and #97 and #123, it's very hard for me to get correctness out of fsnotify, so I was considering writing my own little inotify wrapper anyway, so I'm glad to hear that this is being considered.

For now I think I'll just fork the project to quickly fix/hack the bugs that are impacting me.

from fsnotify.

nathany avatar nathany commented on September 27, 2024

Pull requests are welcome, and once we have more people reviewing and merging pull requests, things should start to move faster.

I think breaking out the low-level platform specific libraries (such as #173) will also help there. It should allow experts in inotify to work on that without worrying about the cross-platform API, and others to tackle cross-platform consistency without dealing with all the low-level details.

from fsnotify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.