From c1b432ee54424c3943dee97ff2dd90c4cc533e9b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 10 Jun 2012 19:08:03 -0400 Subject: [PATCH] run git add --update after inotify is started This way, there's no window where deleted files won't be noticed. --- Command/Watch.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Command/Watch.hs b/Command/Watch.hs index ab0c0ce796..c57b21ac69 100644 --- a/Command/Watch.hs +++ b/Command/Watch.hs @@ -57,10 +57,8 @@ watch :: Annex () #if defined linux_HOST_OS watch = do showAction "scanning" - inRepo $ Git.Command.run "add" [Param "--update"] withStateMVar $ \st -> liftIO $ withINotify $ \i -> do changechan <- atomically newTChan - _ <- forkIO $ commitThread st changechan let hook a = Just $ runHandler st changechan a let hooks = WatchHooks { addHook = hook onAdd @@ -69,7 +67,17 @@ watch = do , delDirHook = hook onDelDir , 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 + -- Notice any files that were deleted before inotify + -- was started. + runStateMVar st $ + inRepo $ Git.Command.run "add" [Param "--update"] putStrLn "(started)" waitForTermination #else