@@ -4,13 +4,14 @@ module Ext.Filewatch where
4
4
5
5
import Ext.Common
6
6
import System.FSNotify
7
- import Control.Concurrent (threadDelay , forkIO )
7
+ import Control.Concurrent (threadDelay )
8
8
import Control.Monad (forever )
9
9
import qualified Data.List as List
10
10
import qualified Control.FoldDebounce as Debounce
11
- import qualified System.Directory as Dir
12
11
import qualified System.FilePath as FP
13
12
13
+
14
+ watch :: FilePath -> ([FilePath ] -> IO () ) -> IO ()
14
15
watch root action =
15
16
trackedForkIO " Ext.Filewatch.watch" $ withManager $ \ mgr -> do
16
17
trigger <-
@@ -26,32 +27,37 @@ watch root action =
26
27
}
27
28
28
29
-- start a watching job (in the background)
29
- watchTree
30
+ _ <- watchTree
30
31
mgr -- manager
31
32
root -- directory to watch
32
33
(const True ) -- predicate
33
34
(\ e -> do
34
35
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
40
44
41
45
-- @TODO it would be better to not listen to these folders in the `watchTree` when available
42
46
-- https://github.com/haskell-fswatch/hfsnotify/issues/101
43
47
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 )
49
53
50
- onlyWhen shouldRefresh $ Debounce. send trigger f
54
+ onlyWhen shouldRefresh $ Debounce. send trigger filepath
51
55
)
52
56
53
57
-- sleep forever (until interrupted)
54
58
forever $ threadDelay 1000000
55
59
60
+
61
+ watchFile :: FilePath -> ([FilePath ] -> IO () ) -> IO ()
56
62
watchFile file action =
57
63
watch (FP. takeDirectory file) action
0 commit comments