{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
module System.FSNotify.Devel (
treeExtAny
, treeExtExists
, doAllEvents
, allEvents
, existsEvents
) where
import Data.Text
import Prelude hiding (FilePath)
import System.FSNotify
import System.FSNotify.Path (hasThisExtension)
import System.FilePath
treeExtExists :: WatchManager
-> FilePath
-> Text
-> (FilePath -> IO ())
-> IO StopListening
treeExtExists :: WatchManager
-> FilePath -> Text -> (FilePath -> IO ()) -> IO (IO ())
treeExtExists WatchManager
man FilePath
dir Text
ext FilePath -> IO ()
action =
WatchManager -> FilePath -> ActionPredicate -> Action -> IO (IO ())
watchTree WatchManager
man FilePath
dir ((FilePath -> Bool) -> ActionPredicate
existsEvents forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip FilePath -> Text -> Bool
hasThisExtension Text
ext) (forall (m :: * -> *).
Monad m =>
(FilePath -> m ()) -> Event -> m ()
doAllEvents FilePath -> IO ()
action)
treeExtAny :: WatchManager
-> FilePath
-> Text
-> (FilePath -> IO ())
-> IO StopListening
treeExtAny :: WatchManager
-> FilePath -> Text -> (FilePath -> IO ()) -> IO (IO ())
treeExtAny WatchManager
man FilePath
dir Text
ext FilePath -> IO ()
action =
WatchManager -> FilePath -> ActionPredicate -> Action -> IO (IO ())
watchTree WatchManager
man FilePath
dir ((FilePath -> Bool) -> ActionPredicate
allEvents forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> b -> a -> c
flip FilePath -> Text -> Bool
hasThisExtension Text
ext) (forall (m :: * -> *).
Monad m =>
(FilePath -> m ()) -> Event -> m ()
doAllEvents FilePath -> IO ()
action)
doAllEvents :: Monad m => (FilePath -> m ()) -> Event -> m ()
doAllEvents :: forall (m :: * -> *).
Monad m =>
(FilePath -> m ()) -> Event -> m ()
doAllEvents FilePath -> m ()
action = FilePath -> m ()
action forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event -> FilePath
eventPath
existsEvents :: (FilePath -> Bool) -> (Event -> Bool)
existsEvents :: (FilePath -> Bool) -> ActionPredicate
existsEvents FilePath -> Bool
filt Event
event =
case Event
event of
Added {FilePath
eventPath :: FilePath
eventPath :: Event -> FilePath
eventPath} -> FilePath -> Bool
filt FilePath
eventPath
Modified {FilePath
eventPath :: FilePath
eventPath :: Event -> FilePath
eventPath} -> FilePath -> Bool
filt FilePath
eventPath
ModifiedAttributes {FilePath
eventPath :: FilePath
eventPath :: Event -> FilePath
eventPath} -> FilePath -> Bool
filt FilePath
eventPath
Event
_ -> Bool
False
allEvents :: (FilePath -> Bool) -> (Event -> Bool)
allEvents :: (FilePath -> Bool) -> ActionPredicate
allEvents FilePath -> Bool
filt = FilePath -> Bool
filt forall b c a. (b -> c) -> (a -> b) -> a -> c
. Event -> FilePath
eventPath