summaryrefslogtreecommitdiff
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
parent6ca8426717af44744d184f4e605e965e840dd16f (diff)
use Win32-inotify
May mean the watcher works on Windows. Untested.
-rw-r--r--Utility/DirWatcher.hs32
-rw-r--r--Utility/Win32Notify.hs15
2 files changed, 30 insertions, 17 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
diff --git a/Utility/Win32Notify.hs b/Utility/Win32Notify.hs
index 3493b9e9a..edde5309c 100644
--- a/Utility/Win32Notify.hs
+++ b/Utility/Win32Notify.hs
@@ -11,32 +11,33 @@ import Common hiding (isDirectory)
import Utility.DirWatcher.Types
import System.Win32.Notify
+import qualified System.PosixCompat.Files as Files
watchDir :: FilePath -> (FilePath -> Bool) -> WatchHooks -> IO WatchManager
watchDir dir ignored hooks = do
scan dir
wm <- initWatchManager
void $ watchDirectory wm dir True [Create, Delete, Modify, Move] handle
- retufn wm
+ return wm
where
handle evt
| ignoredPath ignored (filePath evt) = noop
- | otherwise = case eventToVariety evt of
- Delete
+ | otherwise = case evt of
+ (Deleted _ _)
| isDirectory evt -> runhook delDirHook Nothing
| otherwise -> runhook delHook Nothing
- Create
+ (Created _ _)
| isDirectory evt -> noop
| otherwise -> runhook addHook Nothing
- Modify
+ (Modified _ _)
| isDirectory evt -> noop
{- Add hooks are run when a file is modified for
- compatability with INotify, which calls the add
- hook when a file is closed, and so tends to call
- both add and modify for file modifications. -}
| otherwise -> do
- runHook addHook Nothing
- runHook modifyHook Nothing
+ runhook addHook Nothing
+ runhook modifyHook Nothing
where
runhook h s = maybe noop (\a -> a (filePath evt) s) (h hooks)