diff options
author | Joey Hess <joey@kitenet.net> | 2012-06-12 16:20:56 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-06-12 16:24:06 -0400 |
commit | b240418acc99d5cacc2fdcfe655979517eda9fd4 (patch) | |
tree | 6ab0d8219e43c32409e9d651b8261c75f5a8c96b /Utility | |
parent | 7d2c8133967d2f12cd18cf8f57e91a107e17bedb (diff) |
better optimisation of add check
Now really only done in the startup scan.
It turns out to be quite hard for event handlers to know when the startup
scan is complete. I tried to make addWatch pass that info, but found
threading the state very difficult. For now, a quick hack, using the fast
flag.
Note that it's actually possible for inotify events to come in while the
startup scan is still ongoing. Due to my hack, the expensive check will
be done for files added in such inotify events.
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/Inotify.hs | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/Utility/Inotify.hs b/Utility/Inotify.hs index 5ed016c44..6eb7be31c 100644 --- a/Utility/Inotify.hs +++ b/Utility/Inotify.hs @@ -15,11 +15,7 @@ import qualified System.Posix.Files as Files import System.IO.Error import Control.Exception (throw) -{- A hook is passed some value to act on. - - - - The Bool is False when we're in the intial scan of a directory tree, - - rather than having received a genuine inotify event. -} -type Hook a = Maybe (a -> Bool -> IO ()) +type Hook a = Maybe (a -> IO ()) data WatchHooks = WatchHooks { addHook :: Hook FilePath @@ -94,8 +90,8 @@ watchDir i dir ignored hooks Nothing -> return () Just s | Files.isDirectory s -> recurse fullf - | Files.isSymbolicLink s -> addSymlinkHook <@?> f - | Files.isRegularFile s -> addHook <@?> f + | Files.isSymbolicLink s -> addSymlinkHook <@> f + | Files.isRegularFile s -> addHook <@> f | otherwise -> return () -- Ignore creation events for regular files, which won't be @@ -130,11 +126,10 @@ watchDir i dir ignored hooks hashook h = isJust $ h hooks - runhook h f inscan + runhook h f | ignored f = noop - | otherwise = maybe noop (\a -> a (indir f) inscan) (h hooks) - h <@> f = runhook h f False - h <@?> f = runhook h f True + | otherwise = maybe noop (\a -> a $ indir f) (h hooks) + h <@> f = runhook h f indir f = dir </> f @@ -149,10 +144,10 @@ watchDir i dir ignored hooks Just hook -> tooManyWatches hook dir | otherwise = throw e -tooManyWatches :: (String -> Bool -> IO ()) -> FilePath -> IO () +tooManyWatches :: (String -> IO ()) -> FilePath -> IO () tooManyWatches hook dir = do sysctlval <- querySysctl [Param maxwatches] :: IO (Maybe Integer) - hook (unlines $ basewarning : maybe withoutsysctl withsysctl sysctlval) False + hook $ unlines $ basewarning : maybe withoutsysctl withsysctl sysctlval where maxwatches = "fs.inotify.max_user_watches" basewarning = "Too many directories to watch! (Not watching " ++ dir ++")" |