packages feed

fsnotify 0.0.2 → 0.0.3

raw patch · 2 files changed

+26/−24 lines, 2 filesdep ~hinotifynew-uploader

Dependency ranges changed: hinotify

Files

fsnotify.cabal view
@@ -1,5 +1,5 @@ Name:                   fsnotify-Version:                0.0.2+Version:                0.0.3 Author:                 Mark Dittmer <mark.s.dittmer@gmail.com> Maintainer:             Mark Dittmer <mark.s.dittmer@gmail.com>, Greg Weber <greg@gregweber.info> License:                BSD3@@ -34,7 +34,7 @@   if os(linux)     CPP-Options:        -DOS_Linux     Other-Modules:      System.FSNotify.Linux-    Build-Depends:      hinotify == 0.3.2+    Build-Depends:      hinotify >= 0.3.5 && < 0.4   else     if os(windows)       CPP-Options:      -DOS_Win32@@ -56,7 +56,7 @@ --                 , Glob >= 0.7.1 --                 , system-fileio >= 0.3.8 --                 , system-filepath >= 0.4.6---                 , text >= 0.11.2.0+--                 , text >= 0.11.0 --                 , time >= 1.4  Test-Suite test
src/System/FSNotify/Win32.hs view
@@ -2,6 +2,7 @@ -- Copyright (c) 2012 Mark Dittmer - http://www.markdittmer.org -- Developed for a Google Summer of Code project - http://gsoc2012.markdittmer.org --+{-# OPTIONS_GHC -fno-warn-orphans #-}  module System.FSNotify.Win32        ( FileListener(..)@@ -9,15 +10,12 @@        ) where  import Prelude hiding (FilePath)-import System.IO hiding (FilePath)  import Control.Concurrent.Chan import Control.Monad (when)-import Data.IORef (atomicModifyIORef, newIORef, readIORef)+import Data.IORef (atomicModifyIORef, readIORef) import Data.Time (getCurrentTime, UTCTime)-import Data.Time.Clock.POSIX (posixSecondsToUTCTime)-import Filesystem.Path.CurrentOS (FilePath)-import System.FSNotify.Listener (debounce, FileListener(..))+import System.FSNotify.Listener import System.FSNotify.Path (fp, canonicalizeDirPath) import System.FSNotify.Types import qualified System.Win32.Notify as WNo@@ -39,16 +37,20 @@ fsnEvents timestamp (WNo.Deleted  False name)                   = [Removed (fp name) timestamp] fsnEvents _         _                                           = [] -handleWNoEvent :: IOEvent -> ActionPredicate -> EventChannel -> WNo.Event -> IO ()-handleWNoEvent ior actPred chan inoEvent = do+handleWNoEvent :: ActionPredicate -> EventChannel -> DebouncePayload -> WNo.Event -> IO ()+handleWNoEvent actPred chan dbp inoEvent = do   currentTime <- getCurrentTime-  mapM_ (handleEvent ior actPred chan) (fsnEvents currentTime inoEvent)-handleEvent :: IOEvent -> ActionPredicate -> EventChannel -> Event -> IO ()-handleEvent ior actPred chan event =-  when (actPred event) $ do-    lastEvent <- readIORef ior-    when (not $ debounce lastEvent event) (writeChan chan event)-    atomicModifyIORef ior \_ -> (event, ())+  mapM_ (handleEvent actPred chan dbp) (fsnEvents currentTime inoEvent)+handleEvent :: ActionPredicate -> EventChannel -> DebouncePayload -> Event -> IO ()+handleEvent actPred chan dbp event =+  when (actPred event) $ case dbp of+    (Just (DebounceData epsilon ior)) -> do+      lastEvent <- readIORef ior+      when (not $ debounce epsilon lastEvent event) writeToChan+      atomicModifyIORef ior (\_ -> (event, ()))+    Nothing                           -> writeToChan+  where+    writeToChan = writeChan chan event  instance FileListener WNo.WatchManager where   -- TODO: This should actually lookup a Windows API version and possibly return@@ -58,19 +60,19 @@    killSession = WNo.killWatchManager -  listen watchManager path actPred chan = do+  listen db watchManager path actPred chan = do     path' <- canonicalizeDirPath path-    ior   <- newIORef (Added (fp "") (posixSecondsToUTCTime 0))-    _ <- WNo.watchDirectory watchManager (fp path') False varieties (handler ior actPred chan)+    dbp <- newDebouncePayload db+    _ <- WNo.watchDirectory watchManager (fp path') False varieties (handler actPred chan dbp)     void -  listenRecursive watchManager path actPred chan = do+  listenRecursive db watchManager path actPred chan = do     path' <- canonicalizeDirPath path-    ior   <- newIORef (Added (fp "") (posixSecondsToUTCTime 0))-    _ <- WNo.watchDirectory watchManager (fp path') True varieties (handler ior actPred chan)+    dbp <- newDebouncePayload db+    _ <- WNo.watchDirectory watchManager (fp path') True varieties (handler actPred chan dbp)     void -handler :: IOEvent -> ActionPredicate -> EventChannel -> WNo.Event -> IO ()+handler :: ActionPredicate -> EventChannel -> DebouncePayload -> WNo.Event -> IO () handler = handleWNoEvent  varieties :: [WNo.EventVariety]