run git add --update after inotify is started

This way, there's no window where deleted files won't be noticed.
This commit is contained in:
Joey Hess 2012-06-10 19:08:03 -04:00
parent aae0ba1995
commit c1b432ee54

View file

@ -57,10 +57,8 @@ watch :: Annex ()
#if defined linux_HOST_OS #if defined linux_HOST_OS
watch = do watch = do
showAction "scanning" showAction "scanning"
inRepo $ Git.Command.run "add" [Param "--update"]
withStateMVar $ \st -> liftIO $ withINotify $ \i -> do withStateMVar $ \st -> liftIO $ withINotify $ \i -> do
changechan <- atomically newTChan changechan <- atomically newTChan
_ <- forkIO $ commitThread st changechan
let hook a = Just $ runHandler st changechan a let hook a = Just $ runHandler st changechan a
let hooks = WatchHooks let hooks = WatchHooks
{ addHook = hook onAdd { addHook = hook onAdd
@ -69,7 +67,17 @@ watch = do
, delDirHook = hook onDelDir , delDirHook = hook onDelDir
, errHook = hook onErr , errHook = hook onErr
} }
-- The commit thread is started early, so that the user
-- can immediately begin adding files and having them
-- committed, even while the inotify scan is taking place.
_ <- forkIO $ commitThread st changechan
-- This does not return until the inotify scan is done.
-- That can take some time for large trees.
watchDir i "." (ignored . takeFileName) hooks watchDir i "." (ignored . takeFileName) hooks
-- Notice any files that were deleted before inotify
-- was started.
runStateMVar st $
inRepo $ Git.Command.run "add" [Param "--update"]
putStrLn "(started)" putStrLn "(started)"
waitForTermination waitForTermination
#else #else