@@ -19,6 +19,17 @@ let private handleWatcherEvents (status : FileStatus) (onChange : FileChange ->
19
19
Name = e.Name
20
20
Status = status })
21
21
22
+ let private calcDirsToWatch fileIncludes =
23
+ let dirsToWatch = fileIncludes.Includes |> Seq.map ( fun file -> Globbing.getRoot fileIncludes.BaseDirectory file)
24
+
25
+ // remove subdirectories from watch list so that we don't get duplicate file watchers running
26
+ dirsToWatch
27
+ |> Seq.filter ( fun d ->
28
+ dirsToWatch
29
+ |> Seq.exists ( fun p -> d.StartsWith p && p <> d)
30
+ |> not )
31
+ |> Seq.toList
32
+
22
33
/// Watches the for changes in the matching files.
23
34
/// Returns an IDisposable which allows to dispose all FileSystemWatchers.
24
35
///
@@ -39,14 +50,8 @@ let private handleWatcherEvents (status : FileStatus) (onChange : FileChange ->
39
50
/// )
40
51
///
41
52
let WatchChanges ( onChange : FileChange seq -> unit ) ( fileIncludes : FileIncludes ) =
42
- let dirsToWatch = fileIncludes.Includes |> Seq.map ( fun file -> Globbing.getRoot fileIncludes.BaseDirectory file)
43
-
44
- // remove subdirectories from watch list so that we don't get duplicate file watchers running
45
- let dirsToWatch =
46
- dirsToWatch |> Seq.filter ( fun d ->
47
- dirsToWatch
48
- |> Seq.exists ( fun p -> p.StartsWith d && p <> d)
49
- |> not )
53
+ let dirsToWatch = fileIncludes |> calcDirsToWatch
54
+
50
55
tracefn " dirs to watch: %A " dirsToWatch
51
56
52
57
// we collect changes in a mutable ref cell and wait for a few milliseconds to
@@ -84,7 +89,7 @@ let WatchChanges (onChange : FileChange seq -> unit) (fileIncludes : FileInclude
84
89
( timer: System.Timers.Timer) .Start() )
85
90
86
91
let watchers =
87
- dirsToWatch |> List.ofSeq |> List. map ( fun dir ->
92
+ dirsToWatch |> List.map ( fun dir ->
88
93
tracefn " watching dir: %s " dir
89
94
90
95
let watcher = new FileSystemWatcher( FullName dir, " *.*" )
0 commit comments