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

kqueue: don't immediately remove watches for all files in a directory on Delete event #526

Merged
merged 1 commit into from Oct 15, 2022

Commits on Oct 15, 2022

  1. kqueue: don't immediately remove watches for all files in a directory…

    … on Delete event
    
    The problem was that that on Delete events for directories it would call
    Watcher.Remove() for all files in that directory too. This is fine if you call
    w.Remove() from the application, but if you rm -rf a directory the directory
    itself tends to be the first remove event (on FreeBSD at least):
    
    	DELETE WRITE  /tmp/xxx
    	DELETE        /tmp/xxx/a
    	DELETE        /tmp/xxx/b
    	DELETE        /tmp/xxx/c
    	DELETE        /tmp/xxx/d
    	DELETE        /tmp/xxx/e
    	DELETE        /tmp/xxx/f
    	DELETE        /tmp/xxx/g
    
    So what would happen is that the internal state for /tmp/xxx/a etc. would get
    removed, and when the event gets processed we no longer have access to it.
    
    Move Remove() to remove() with a flag to control removing files. If a watched
    directory is removed then the files will emit their own delete event, so we
    don't really need to do this.
    
    Fixes #514
    
    Also:
    
    - Don't send Remove|Write events; that's never really useful: if it's
      gone, then it's gone. No other backends do this.
    
    - Save a stat call by checking the readdir error instead.
    
    - Don't stat every directory; this isn't really needed, and getting a
      write event before a delete is fine (and this didn't suppress the
      write even anyway).
    
    - Add test/kqueue.c; just a simple implementation to test things.
    arp242 committed Oct 15, 2022
    Configuration menu
    Copy the full SHA
    4bfaa7f View commit details
    Browse the repository at this point in the history