diff options
author | Joey Hess <joey@kitenet.net> | 2012-06-06 23:20:09 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-06-06 23:20:09 -0400 |
commit | b8ae9528ab6d18f8b16c71e455d9f9077fc6e97b (patch) | |
tree | ca190a1d4891061e78a331beb018a62344890bdd /Command | |
parent | b8f85f7a82009f3480abaedae510b4db1c3b3f3a (diff) |
refactor
Diffstat (limited to 'Command')
-rw-r--r-- | Command/Watch.hs | 40 |
1 files changed, 11 insertions, 29 deletions
diff --git a/Command/Watch.hs b/Command/Watch.hs index 478631100..b812691bf 100644 --- a/Command/Watch.hs +++ b/Command/Watch.hs @@ -48,10 +48,14 @@ start = notBareRepo $ do mvar <- liftIO $ newMVar state next $ next $ liftIO $ withINotify $ \i -> do let hook a = Just $ runAnnex mvar a - watchDir i "." (ignored . takeFileName) - (hook onTooMany) - (hook onAdd) (hook onAddSymlink) - (hook onDel) (hook onDelDir) + let hooks = WatchHooks + { addHook = hook onAdd + , delHook = hook onDel + , addSymlinkHook = hook onAddSymlink + , delDirHook = hook onDelDir + , errHook = hook onErr + } + watchDir i "." (ignored . takeFileName) hooks putStrLn "(started)" waitForTermination return True @@ -129,31 +133,9 @@ onDelDir :: FilePath -> Annex () onDelDir dir = inRepo $ Git.Command.run "rm" [Params "--quiet -r --cached --ignore-unmatch --", File dir] -{- There are too many directories for inotify to watch them all. -} -onTooMany :: FilePath -> Annex () -onTooMany dir = do - sysctlval <- liftIO $ runsysctl [Param maxwatches] - warning $ unlines $ - basewarning : maybe withoutsysctl withsysctl sysctlval - where - maxwatches = "fs.inotify.max_user_watches" - basewarning = "Too many directories to watch! (Not watching " ++ dir ++")" - withoutsysctl = ["Increase the value in /proc/sys/fs/inotify/max_user_watches"] - withsysctl n = let new = n * 10 in - [ "Increase the limit by running:" - , " echo " ++ maxwatches ++ "=" ++ show new ++ - " | sudo tee -a /etc/sysctl.conf; sudo sysctl -p" - ] - runsysctl ps = do - v <- catchMaybeIO $ hPipeFrom "sysctl" $ toCommand ps - case v of - Nothing -> return Nothing - Just (pid, h) -> do - val <- parsesysctl <$> liftIO (hGetContentsStrict h) - void $ getProcessStatus True False $ processID pid - return val - parsesysctl :: String -> Maybe Integer - parsesysctl s = readish =<< lastMaybe (words s) +{- Called when there's an error with inotify. -} +onErr :: String -> Annex () +onErr = warning {- Adds a symlink to the index, without ever accessing the actual symlink - on disk. -} |