diff --git a/import.go b/import.go index 576b508bb2e08b9477f3a253fae6cef0b94e0fa6..b0963ad593b9fa6f2b76f75fdd42a4ce7e57481c 100644 --- a/import.go +++ b/import.go @@ -93,10 +93,21 @@ func (s *Settings[C]) importStreams() { func (s *Settings[C]) importFiles() { s.fileWatch.Lock() - defer s.fileWatch.Unlock() // new files may have been added - s.fileWatch.watchList = make(map[string]string) + tmpWatchList := make(map[string]string) + + defer func() { + s.fileWatch.watchList = tmpWatchList + s.fileWatch.Unlock() + }() + + errorCount := len(s.errors) + defer func() { + if len(s.errors) > errorCount { + s.notifyErrorHooks() + } + }() for _, d := range s.files.directories { fn := path.Join(d, s.files.name+s.files.format.Extension()) @@ -112,7 +123,7 @@ func (s *Settings[C]) importFiles() { s.importStream(reader{s.files.format, r}) f.Close() - s.fileWatch.watchList[fn] = fn + tmpWatchList[fn] = fn } @@ -125,8 +136,9 @@ func (s *Settings[C]) importFiles() { continue } s.importStream(reader{f.format, r}) + r.Close() - s.fileWatch.watchList[f.path] = f.path + tmpWatchList[f.path] = f.path } }