From 634d87d1e36564f08ee447c072be93dd834de629 Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Sun, 23 Oct 2022 09:48:15 +0200 Subject: [PATCH] refactor assign file list --- import.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/import.go b/import.go index 576b508..b0963ad 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 } } -- GitLab