@@ -33,41 +33,40 @@ internal sealed class PathsWatcher : IDisposable {
3333
3434 public PathsWatcher ( string [ ] paths , Action onChanged , ILogger log ) {
3535 _log = log ;
36- if ( paths ? . Length == 0 ) {
36+ paths = paths != null ? paths . Where ( p => Path . IsPathRooted ( p ) ) . ToArray ( ) : Array . Empty < string > ( ) ;
37+ if ( paths . Length == 0 ) {
3738 return ;
3839 }
3940
4041 _onChanged = onChanged ;
4142
42- var list = new List < FileSystemWatcher > ( ) ;
4343 var reduced = ReduceToCommonRoots ( paths ) ;
4444 foreach ( var p in reduced ) {
4545 try {
4646 if ( ! Directory . Exists ( p ) ) {
4747 continue ;
4848 }
49- } catch ( IOException ex ) {
49+ } catch ( IOException ex ) {
5050 _log . TraceMessage ( $ "Unable to access directory { p } , exception { ex . Message } ") ;
5151 continue ;
5252 }
5353
5454 try {
5555 var fsw = new System . IO . FileSystemWatcher ( p ) {
5656 IncludeSubdirectories = true ,
57- EnableRaisingEvents = true
57+ EnableRaisingEvents = true ,
58+ NotifyFilter = NotifyFilters . FileName | NotifyFilters . DirectoryName
5859 } ;
5960
60- fsw . Changed += OnChanged ;
6161 fsw . Created += OnChanged ;
6262 fsw . Deleted += OnChanged ;
6363
6464 _disposableBag
65- . Add ( ( ) => fsw . Changed -= OnChanged )
6665 . Add ( ( ) => fsw . Created -= OnChanged )
6766 . Add ( ( ) => fsw . Deleted -= OnChanged )
6867 . Add ( ( ) => fsw . EnableRaisingEvents = false )
6968 . Add ( fsw ) ;
70- } catch ( ArgumentException ex ) {
69+ } catch ( ArgumentException ex ) {
7170 _log . TraceMessage ( $ "Unable to create file watcher for { p } , exception { ex . Message } ") ;
7271 }
7372 }
@@ -84,9 +83,9 @@ private void OnChanged(object sender, FileSystemEventArgs e) {
8483
8584 private void TimerProc ( object o ) {
8685 lock ( _lock ) {
87- if ( ! _changedSinceLastTick && _throttleTimer != null ) {
86+ if ( _changedSinceLastTick ) {
8887 ThreadPool . QueueUserWorkItem ( _ => _onChanged ( ) ) ;
89- _throttleTimer . Dispose ( ) ;
88+ _throttleTimer ? . Dispose ( ) ;
9089 _throttleTimer = null ;
9190 }
9291 _changedSinceLastTick = false ;
0 commit comments