This commit is contained in:
Joey Hess 2012-06-06 23:20:09 -04:00
parent b8f85f7a82
commit b8ae9528ab
2 changed files with 68 additions and 49 deletions

View file

@ -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. -}