This commit is contained in:
Joey Hess 2012-06-04 17:17:05 -04:00
parent ce9dc15ea0
commit 529a3721e1

View file

@ -83,8 +83,8 @@ watchDir i dir ignored add addsymlink del deldir
-- Ignore creation events for regular files, which won't be -- Ignore creation events for regular files, which won't be
-- done being written when initially created, but handle for -- done being written when initially created, but handle for
-- directories and symlinks. -- directories and symlinks.
go (Created { isDirectory = True, filePath = subdir }) = recurse $ indir subdir go (Created { isDirectory = isd, filePath = f })
go (Created { isDirectory = False, filePath = f }) | isd = recurse $ indir f
| isJust addsymlink = | isJust addsymlink =
whenM (filetype Files.isSymbolicLink f) $ whenM (filetype Files.isSymbolicLink f) $
addsymlink <@> f addsymlink <@> f
@ -96,12 +96,18 @@ watchDir i dir ignored add addsymlink del deldir
-- When a file or directory is moved in, walk it to add new -- When a file or directory is moved in, walk it to add new
-- stuff. -- stuff.
go (MovedIn { filePath = f }) = walk f go (MovedIn { filePath = f }) = walk f
go (MovedOut { isDirectory = True, filePath = d }) = deldir <@> d go (MovedOut { isDirectory = isd, filePath = f })
go (MovedOut { filePath = f }) = del <@> f | isd = deldir <@> f
go (Deleted { isDirectory = True, filePath = d }) = | otherwise = del <@> f
notexist d $ deldir <@> d -- Verify that the deleted item really doesn't exist,
go (Deleted { filePath = f }) = -- since there can be spurious deletion events for items
notexist f $ del <@> f -- in a directory that has been moved out, but is still
-- being watched.
go (Deleted { isDirectory = isd, filePath = f })
| isd = guarded $ deldir <@> f
| otherwise = guarded $ del <@> f
where
guarded = unlessM (filetype (const True) f)
go _ = noop go _ = noop
Just a <@> f = a $ indir f Just a <@> f = a $ indir f
@ -111,12 +117,6 @@ watchDir i dir ignored add addsymlink del deldir
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