workaround other part of moved directory problem

This fixes the scenario where:

* directory foo is moved away (and still watched)
* a new directory foo is made
* file (or directory) foo/bar is created
* the old directory's file (or directory) "bar" is deleted

We don't want a deletion event for foo/bar in this case.
This commit is contained in:
Joey Hess 2012-06-04 14:46:09 -04:00
parent fa9d479fd1
commit 47f8f43715

View file

@ -98,16 +98,25 @@ watchDir i dir ignored add addsymlink del deldir
go (MovedIn { filePath = f }) = walk f go (MovedIn { filePath = f }) = walk f
go (MovedOut { isDirectory = True, filePath = d }) = deldir <@> d go (MovedOut { isDirectory = True, filePath = d }) = deldir <@> d
go (MovedOut { filePath = f }) = del <@> f go (MovedOut { filePath = f }) = del <@> f
go (Deleted { isDirectory = True, filePath = d }) = deldir <@> d go (Deleted { isDirectory = True, filePath = d }) =
go (Deleted { filePath = f }) = del <@> f notexist d $ deldir <@> d
go (Deleted { filePath = f }) =
notexist f $ del <@> f
go _ = noop go _ = noop
Just a <@> f = a $ indir f Just a <@> f = a $ indir f
Nothing <@> _ = noop Nothing <@> _ = noop
indir f = dir </> f indir f = dir </> f
filetype t f = catchBoolIO $ t <$> getSymbolicLinkStatus (indir f) filetype t f = catchBoolIO $ t <$> getSymbolicLinkStatus (indir f)
-- Check that a file or directory does not exist.
-- This is used when there could be a spurious deletion
-- event for an item in a directory that has been moved away
-- but is still being watched.
notexist f = unlessM (filetype (const True) f)
{- Pauses the main thread, letting children run until program termination. -} {- Pauses the main thread, letting children run until program termination. -}
waitForTermination :: IO () waitForTermination :: IO ()
waitForTermination = do waitForTermination = do