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

Using NativeManager on Linux, moving a watched directory results in incorrect behavior #54

Open
mlacorte opened this issue Jan 30, 2015 · 3 comments
Labels

Comments

@mlacorte
Copy link
Contributor

Description

After moving a directory that hfsnotify is watching, hfsnotify reports changes inside that directory as if it had not been moved.

Only the NativeManager on Linux is affected.

I have not tested the NativeManager on OS X or Windows.

Steps to Reproduce
  1. Run the following Bash script:

    mkdir -p /tmp/example
  2. Run the following Haskell program:

    {-# LANGUAGE OverloadedStrings #-}
    
    import System.FSNotify
    import Control.Concurrent
    import Control.Monad
    
    main :: IO ()
    main = withManager $ \mgr -> do
       _ <- watchTree mgr "/tmp/example" (const True) print
       forever (threadDelay maxBound)
  3. While the Haskell program is running, run the following Bash script:

    cd /tmp/example
    
    mkdir foo
    touch foo/test
    
    mv foo bar
    
    touch bar/test
    rm -rf bar
Expected Output
Added (FilePath "/tmp/example/foo/test") <TIMESTAMP>
Removed (FilePath "/tmp/example/foo/test") <TIMESTAMP>
Added (FilePath "/tmp/example/bar/test") <TIMESTAMP>
Modified (FilePath "/tmp/example/bar/test") <TIMESTAMP>
Removed (FilePath "/tmp/example/bar/test") <TIMESTAMP>
Actual Output

The following is printed from the Haskell program:

Added (FilePath "/tmp/example/foo/test") <TIMESTAMP>
Modified (FilePath "/tmp/example/foo/test") <TIMESTAMP>
Removed (FilePath "/tmp/example/foo/test") <TIMESTAMP>
@gregwebs
Copy link
Member

My guess is that on the whole the behavior around moving a directory that is watched is undefined. We probably need to allow the user to specify whether a directory should be watched after moved, but a possible default that may work cross-platform is to stop watching it.

@thomasjm thomasjm added the bug label May 29, 2018
@thomasjm
Copy link
Contributor

This is just how inotify works--when you move the directory it is moving the inode but it's still watching the same inode.

Solution: we should detect the IN_MOVED_FROM and IN_MOVED_TO events and emit events/update watches accordingly. For example, if a folder is moved outside of a watched tree, we should stop watching it entirely.

@erikd
Copy link

erikd commented Jul 8, 2018

Just got hit by a variant on this myself using the conduit version.

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

No branches or pull requests

4 participants