From fa9d479fd1102efeebaafca66d7747bf07604ecb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 4 Jun 2012 14:31:06 -0400 Subject: add explict test that a closed file even is on a regular file There are two reasons for this test. First, there could be a fifo or other non-regular file that was closed. Second, this test avoids ugliness when a subdirectory is moved out of the top of the watch directory to elsewhere, and a file added to it. Since the subdirectory has moved, the file won't be present under the old location, and nothing will be done. I cannot find a way to stop watching such directories, at least not without a lot of pain. The inotify interface in Haskell doesn't make it easy to stop watching a given subdirectory when it's moved out; it would require keeping a map of all watch handles that is shared between threads. This workaround avoids the problem in most cases; the only remaining case being deletion of a file from a moved subdirectory. --- Utility/Inotify.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Utility/Inotify.hs') diff --git a/Utility/Inotify.hs b/Utility/Inotify.hs index dc4c352bf..c5caf0655 100644 --- a/Utility/Inotify.hs +++ b/Utility/Inotify.hs @@ -86,13 +86,13 @@ watchDir i dir ignored add addsymlink del deldir go (Created { isDirectory = True, filePath = subdir }) = recurse $ indir subdir go (Created { isDirectory = False, filePath = f }) | isJust addsymlink = - ifM (catchBoolIO $ Files.isSymbolicLink <$> getSymbolicLinkStatus (indir f)) - ( addsymlink <@> f - , noop - ) + whenM (filetype Files.isSymbolicLink f) $ + addsymlink <@> f | otherwise = noop -- Closing a file is assumed to mean it's done being written. - go (Closed { isDirectory = False, maybeFilePath = Just f }) = add <@> f + go (Closed { isDirectory = False, maybeFilePath = Just f }) = + whenM (filetype Files.isRegularFile f) $ + add <@> f -- When a file or directory is moved in, walk it to add new -- stuff. go (MovedIn { filePath = f }) = walk f @@ -106,6 +106,7 @@ watchDir i dir ignored add addsymlink del deldir Nothing <@> _ = noop indir f = dir f + filetype t f = catchBoolIO $ t <$> getSymbolicLinkStatus (indir f) {- Pauses the main thread, letting children run until program termination. -} waitForTermination :: IO () -- cgit v1.2.3