From 142ba4db72679fa2b17eb4ae33ac7d9764a71b09 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 30 Sep 2013 13:11:26 -0400 Subject: assistant: More robust inotify handling; avoid crashing if a directory cannot be read. --- Utility/INotify.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'Utility/INotify.hs') diff --git a/Utility/INotify.hs b/Utility/INotify.hs index e9071d906..ffdad8be3 100644 --- a/Utility/INotify.hs +++ b/Utility/INotify.hs @@ -54,11 +54,12 @@ watchDir i dir ignored hooks -- scan come before real inotify events. lock <- newLock let handler event = withLock lock (void $ go event) - void (addWatch i watchevents dir handler) - `catchIO` failedaddwatch - withLock lock $ - mapM_ scan =<< filter (not . dirCruft) <$> - getDirectoryContents dir + flip catchNonAsync failedwatch $ do + void (addWatch i watchevents dir handler) + `catchIO` failedaddwatch + withLock lock $ + mapM_ scan =<< filter (not . dirCruft) <$> + getDirectoryContents dir where recurse d = watchDir i d ignored hooks @@ -149,12 +150,14 @@ watchDir i dir ignored hooks -- disk full error. | isFullError e = case errHook hooks of - Nothing -> throw e + Nothing -> error $ "failed to add inotify watch on directory " ++ dir ++ " (" ++ show e ++ ")" Just hook -> tooManyWatches hook dir -- The directory could have been deleted. | isDoesNotExistError e = return () | otherwise = throw e + failedwatch e = hPutStrLn stderr $ "failed to add watch on directory " ++ dir ++ " (" ++ show e ++ ")" + tooManyWatches :: (String -> Maybe FileStatus -> IO ()) -> FilePath -> IO () tooManyWatches hook dir = do sysctlval <- querySysctl [Param maxwatches] :: IO (Maybe Integer) -- cgit v1.2.3