summaryrefslogtreecommitdiff
path: root/Utility/Kqueue.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-06-18 23:47:48 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-06-18 23:49:07 -0400
commit7a09d74319c0e68dddfa2cf1979731a030e8881e (patch)
treebc4acc8901ef7aa80091b29ba3ce57a6654c811a /Utility/Kqueue.hs
parent9b7f929e96531ea3e8b93880ab130179c2fd5107 (diff)
lifted out the kqueue and inotify to a generic DirWatcher interface
Kqueue code for dispatching events is not tested and probably doesn't build.
Diffstat (limited to 'Utility/Kqueue.hs')
-rw-r--r--Utility/Kqueue.hs25
1 files changed, 25 insertions, 0 deletions
diff --git a/Utility/Kqueue.hs b/Utility/Kqueue.hs
index 5b4920f2f..30218bc29 100644
--- a/Utility/Kqueue.hs
+++ b/Utility/Kqueue.hs
@@ -15,9 +15,11 @@ module Utility.Kqueue (
changedFile,
isAdd,
isDelete,
+ runHooks,
) where
import Common
+import Utility.Types.DirWatcher
import System.Posix.Types
import Foreign.C.Types
@@ -187,3 +189,26 @@ handleChange (Kqueue h dirmap pruner) fd olddirinfo =
-- remove it from our map.
newmap <- removeSubDir dirmap (dirName olddirinfo)
return (Kqueue h newmap pruner, [])
+
+{- Processes changes on the Kqueue, calling the hooks as appropriate.
+ - Never returns. -}
+runHooks :: Kqueue -> WatchHooks -> IO ()
+runHooks kq hooks = do
+ (kq', changes) <- Kqueue.waitChange kq
+ forM_ changes $ dispatch kq'
+ runHooks kq' hooks
+ where
+ -- Kqueue returns changes for both whole directories
+ -- being added and deleted, and individual files being
+ -- added and deleted.
+ dispatch q change status
+ | isAdd change = withstatus s (dispatchadd q)
+ | isDelete change = callhook delDirHook change
+ dispatchadd q change s
+ | Files.isSymbolicLink = callhook addSymlinkHook change
+ | Files.isDirectory = print $ "TODO: recursive directory add: " ++ show change
+ | Files.isRegularFile = callhook addHook change
+ | otherwise = noop
+ callhook h change = hooks h $ changedFile change
+ withstatus change a = maybe noop (a change) =<<
+ (catchMaybeIO (getSymbolicLinkStatus (changedFile change)