@@ -4,13 +4,14 @@ module Ext.Filewatch where
44
55import Ext.Common
66import System.FSNotify
7- import Control.Concurrent (threadDelay , forkIO )
7+ import Control.Concurrent (threadDelay )
88import Control.Monad (forever )
99import qualified Data.List as List
1010import qualified Control.FoldDebounce as Debounce
11- import qualified System.Directory as Dir
1211import qualified System.FilePath as FP
1312
13+
14+ watch :: FilePath -> ([FilePath ] -> IO () ) -> IO ()
1415watch root action =
1516 trackedForkIO " Ext.Filewatch.watch" $ withManager $ \ mgr -> do
1617 trigger <-
@@ -26,32 +27,37 @@ watch root action =
2627 }
2728
2829 -- start a watching job (in the background)
29- watchTree
30+ _ <- watchTree
3031 mgr -- manager
3132 root -- directory to watch
3233 (const True ) -- predicate
3334 (\ e -> do
3435 let
35- f = case e of
36- Added f _ _ -> f
37- Modified f _ _ -> f
38- Removed f _ _ -> f
39- Unknown f _ _ _ -> f
36+ filepath = case e of
37+ Added f _ _ -> f
38+ Modified f _ _ -> f
39+ ModifiedAttributes f _ _ -> f
40+ Removed f _ _ -> f
41+ WatchedDirectoryRemoved f _ _ -> f
42+ CloseWrite f _ _ -> f
43+ Unknown f _ _ _ -> f
4044
4145 -- @TODO it would be better to not listen to these folders in the `watchTree` when available
4246 -- https://github.com/haskell-fswatch/hfsnotify/issues/101
4347 shouldRefresh = do
44- not (List. isInfixOf " .git" f )
45- && not (List. isInfixOf " elm-stuff" f )
46- && not (List. isInfixOf " node_modules" f )
47- && not (List. isInfixOf " data" f )
48- && not (List. isInfixOf " elm-pkg-js-includes.min.js" f )
48+ not (List. isInfixOf " .git" filepath )
49+ && not (List. isInfixOf " elm-stuff" filepath )
50+ && not (List. isInfixOf " node_modules" filepath )
51+ && not (List. isInfixOf " data" filepath )
52+ && not (List. isInfixOf " elm-pkg-js-includes.min.js" filepath )
4953
50- onlyWhen shouldRefresh $ Debounce. send trigger f
54+ onlyWhen shouldRefresh $ Debounce. send trigger filepath
5155 )
5256
5357 -- sleep forever (until interrupted)
5458 forever $ threadDelay 1000000
5559
60+
61+ watchFile :: FilePath -> ([FilePath ] -> IO () ) -> IO ()
5662watchFile file action =
5763 watch (FP. takeDirectory file) action
0 commit comments