summaryrefslogtreecommitdiff
path: root/Assistant
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@fischer.debian.org>2012-06-19 02:13:39 +0000
committerGravatar Joey Hess <joeyh@fischer.debian.org>2012-06-19 02:13:39 +0000
commit22b563408bf08158872ddb8e65c16f36b0ab712d (patch)
tree44e87c09f43ca2a20b2f817be131e43c036b3527 /Assistant
parente16455327247656bc47e331be710d6bd58b2675f (diff)
refactor
Diffstat (limited to 'Assistant')
-rw-r--r--Assistant/Watcher.hs36
1 files changed, 23 insertions, 13 deletions
diff --git a/Assistant/Watcher.hs b/Assistant/Watcher.hs
index e2dd5cd2a..7e0a16f40 100644
--- a/Assistant/Watcher.hs
+++ b/Assistant/Watcher.hs
@@ -60,18 +60,9 @@ needLsof = error $ unlines
watchThread :: ThreadState -> DaemonStatusHandle -> ChangeChan -> IO ()
#ifdef WITH_INOTIFY
watchThread st dstatus changechan = withINotify $ \i -> do
- runThreadState st $
- showAction "scanning"
- -- This does not return until the startup scan is done.
- -- That can take some time for large trees.
- watchDir i "." ignored hooks
- runThreadState st $
- modifyDaemonStatus dstatus $ \s -> s { scanComplete = True }
- -- Notice any files that were deleted before inotify
- -- was started.
- runThreadState st $ do
- inRepo $ Git.Command.run "add" [Param "--update"]
- showAction "started"
+ statupScan st dstatus $
+ watchDir i "." ignored hooks
+ -- Let the inotify thread run.
waitForTermination
where
hook a = Just $ runHandler st dstatus changechan a
@@ -84,7 +75,10 @@ watchThread st dstatus changechan = withINotify $ \i -> do
}
#else
#ifdef WITH_KQUEUE
-watchThread st dstatus changechan = go =<< Kqueue.initKqueue "." ignored
+watchThread st dstatus changechan = do
+ kq <- statupScan st dstatus $
+ Kqueue.initKqueue "." ignored
+ go kq
where
go kq = do
(kq', changes) <- Kqueue.waitChange kq
@@ -95,6 +89,22 @@ watchThread = undefined
#endif /* WITH_KQUEUE */
#endif /* WITH_INOTIFY */
+{- Initial scartup scan. The action should return once the scan is complete. -}
+statupScan :: ThreadState -> DaemonStatusHandle -> IO a -> IO a
+statupScan st dstatus scanner = do
+ runThreadState st $
+ showAction "scanning"
+ r <- scanner
+ runThreadState st $
+ modifyDaemonStatus dstatus $ \s -> s { scanComplete = True }
+
+ -- Notice any files that were deleted before watching was started.
+ runThreadState st $ do
+ inRepo $ Git.Command.run "add" [Param "--update"]
+ showAction "started"
+
+ return r
+
ignored :: FilePath -> Bool
ignored = ig . takeFileName
where