summaryrefslogtreecommitdiff
path: root/Utility/DirWatcher.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-11-12 17:17:50 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-11-12 17:29:29 -0400
commitbb2e98c8f1b5b6e1eecf1c5f7ca5fa37b8c6f8a7 (patch)
treeb56b1be9dba41b44c1eb861fbb2ea39989e00f43 /Utility/DirWatcher.hs
parent6ca8426717af44744d184f4e605e965e840dd16f (diff)
use Win32-inotify
May mean the watcher works on Windows. Untested.
Diffstat (limited to 'Utility/DirWatcher.hs')
-rw-r--r--Utility/DirWatcher.hs32
1 files changed, 22 insertions, 10 deletions
diff --git a/Utility/DirWatcher.hs b/Utility/DirWatcher.hs
index d28381fae..5231286fc 100644
--- a/Utility/DirWatcher.hs
+++ b/Utility/DirWatcher.hs
@@ -1,10 +1,10 @@
{- generic directory watching interface
-
- - Uses inotify, or kqueue, or fsevents to watch a directory
+ - Uses inotify, or kqueue, or fsevents, or win32-notify to watch a directory
- (and subdirectories) for changes, and runs hooks for different
- sorts of events as they occur.
-
- - Copyright 2012 Joey Hess <joey@kitenet.net>
+ - Copyright 2012-2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -27,11 +27,15 @@ import Control.Concurrent
import qualified Utility.FSEvents as FSEvents
import qualified System.OSX.FSEvents as FSEvents
#endif
+#if WITH_WIN32NOTIFY
+import qualified Utility.Win32Notify as Win32Notify
+import qualified System.Win32.Notify as Win32Notify
+#endif
type Pruner = FilePath -> Bool
canWatch :: Bool
-#if (WITH_INOTIFY || WITH_KQUEUE || WITH_FSEVENTS)
+#if (WITH_INOTIFY || WITH_KQUEUE || WITH_FSEVENTS || WITH_WIN32NOTIFY)
canWatch = True
#else
#if defined linux_HOST_OS
@@ -47,7 +51,7 @@ canWatch = False
- OTOH, with kqueue, often only one event is received, indicating the most
- recent state of the file. -}
eventsCoalesce :: Bool
-#if WITH_INOTIFY
+#if (WITH_INOTIFY || WITH_WIN32NOTIFY)
eventsCoalesce = False
#else
#if (WITH_KQUEUE || WITH_FSEVENTS)
@@ -68,7 +72,7 @@ eventsCoalesce = undefined
- still being written to, and then no add event will be received once the
- writer closes it. -}
closingTracked :: Bool
-#if (WITH_INOTIFY || WITH_FSEVENTS)
+#if (WITH_INOTIFY || WITH_FSEVENTS || WITH_WIN32NOTIFY)
closingTracked = True
#else
#if WITH_KQUEUE
@@ -83,7 +87,7 @@ closingTracked = undefined
- Fsevents generates events when an existing file is reopened and rewritten,
- but not necessarily when it's opened once and modified repeatedly. -}
modifyTracked :: Bool
-#if (WITH_INOTIFY || WITH_FSEVENTS)
+#if (WITH_INOTIFY || WITH_FSEVENTS || WITH_WIN32NOTIFY)
modifyTracked = True
#else
#if WITH_KQUEUE
@@ -119,27 +123,35 @@ watchDir :: FilePath -> Pruner -> WatchHooks -> (IO FSEvents.EventStream -> IO F
watchDir dir prune hooks runstartup =
runstartup $ FSEvents.watchDir dir prune hooks
#else
+#if WITH_WIN32NOTIFY
+type DirWatcherHandle = Win32Notify.WatchManager
+watchDir :: FilePath -> Pruner -> WatchHooks -> (IO Win32Notify.WatchManager -> IO Win32Notify.WatchManager) -> IO DirWatcherHandle
+watchDir dir prune hooks runstartup =
+ runstartup $ Win32Notify.watchDir dir prune hooks
+#else
type DirWatcherHandle = ()
watchDir :: FilePath -> Pruner -> WatchHooks -> (IO () -> IO ()) -> IO DirWatcherHandle
watchDir = undefined
#endif
#endif
#endif
+#endif
-#if WITH_INOTIFY
stopWatchDir :: DirWatcherHandle -> IO ()
+#if WITH_INOTIFY
stopWatchDir = INotify.killINotify
#else
#if WITH_KQUEUE
-stopWatchDir :: DirWatcherHandle -> IO ()
stopWatchDir = killThread
#else
#if WITH_FSEVENTS
-stopWatchDir :: DirWatcherHandle -> IO ()
stopWatchDir = FSEvents.eventStreamDestroy
#else
-stopWatchDir :: DirWatcherHandle -> IO ()
+#if WITH_WIN32NOTIFY
+stopWatchDir = Win32Notify.killWatchManager
+#else
stopWatchDir = undefined
#endif
#endif
#endif
+#endif