From 47f8f43715f355e141fc2d57ce7f72bdda75b5d6 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 4 Jun 2012 14:46:09 -0400 Subject: 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. --- Utility/Inotify.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Utility') diff --git a/Utility/Inotify.hs b/Utility/Inotify.hs index c5caf0655..320f45525 100644 --- a/Utility/Inotify.hs +++ b/Utility/Inotify.hs @@ -98,16 +98,25 @@ watchDir i dir ignored add addsymlink del deldir go (MovedIn { filePath = f }) = walk f go (MovedOut { isDirectory = True, filePath = d }) = deldir <@> d go (MovedOut { filePath = f }) = del <@> f - go (Deleted { isDirectory = True, filePath = d }) = deldir <@> d - go (Deleted { filePath = f }) = del <@> f + go (Deleted { isDirectory = True, filePath = d }) = + notexist d $ deldir <@> d + go (Deleted { filePath = f }) = + notexist f $ del <@> f go _ = noop Just a <@> f = a $ indir f Nothing <@> _ = noop indir f = dir 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. -} waitForTermination :: IO () waitForTermination = do -- cgit v1.2.3