refactor
This commit is contained in:
parent
e164553272
commit
22b563408b
1 changed files with 23 additions and 13 deletions
|
@ -60,18 +60,9 @@ needLsof = error $ unlines
|
||||||
watchThread :: ThreadState -> DaemonStatusHandle -> ChangeChan -> IO ()
|
watchThread :: ThreadState -> DaemonStatusHandle -> ChangeChan -> IO ()
|
||||||
#ifdef WITH_INOTIFY
|
#ifdef WITH_INOTIFY
|
||||||
watchThread st dstatus changechan = withINotify $ \i -> do
|
watchThread st dstatus changechan = withINotify $ \i -> do
|
||||||
runThreadState st $
|
statupScan st dstatus $
|
||||||
showAction "scanning"
|
watchDir i "." ignored hooks
|
||||||
-- This does not return until the startup scan is done.
|
-- Let the inotify thread run.
|
||||||
-- 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"
|
|
||||||
waitForTermination
|
waitForTermination
|
||||||
where
|
where
|
||||||
hook a = Just $ runHandler st dstatus changechan a
|
hook a = Just $ runHandler st dstatus changechan a
|
||||||
|
@ -84,7 +75,10 @@ watchThread st dstatus changechan = withINotify $ \i -> do
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifdef WITH_KQUEUE
|
#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
|
where
|
||||||
go kq = do
|
go kq = do
|
||||||
(kq', changes) <- Kqueue.waitChange kq
|
(kq', changes) <- Kqueue.waitChange kq
|
||||||
|
@ -95,6 +89,22 @@ watchThread = undefined
|
||||||
#endif /* WITH_KQUEUE */
|
#endif /* WITH_KQUEUE */
|
||||||
#endif /* WITH_INOTIFY */
|
#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 :: FilePath -> Bool
|
||||||
ignored = ig . takeFileName
|
ignored = ig . takeFileName
|
||||||
where
|
where
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue