From b83d77aace7ef6ea0737b25e89b127e79d9d72c4 Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Sun, 23 Oct 2022 10:45:36 +0200 Subject: [PATCH] fix deleted files must not be removed from the watch list --- import.go | 10 ++-------- watch.go | 8 ++++---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/import.go b/import.go index 70be576..3511cce 100644 --- a/import.go +++ b/import.go @@ -94,11 +94,7 @@ func (s *Settings[C]) importFiles() { s.fileWatch.Lock() - // new files may have been added - tmpWatchList := make(map[string]bool) - defer func() { - s.fileWatch.watchList = tmpWatchList s.fileWatch.Unlock() }() @@ -122,9 +118,6 @@ func (s *Settings[C]) importFiles() { r := (io.Reader)(f) s.importStream(reader{s.files.format, r}) f.Close() - - tmpWatchList[fn] = true - } for _, f := range s.files.files { @@ -135,10 +128,11 @@ func (s *Settings[C]) importFiles() { r.Close() continue } + s.importStream(reader{f.format, r}) r.Close() - tmpWatchList[f.path] = true + } } diff --git a/watch.go b/watch.go index 52967e7..c24f3ba 100644 --- a/watch.go +++ b/watch.go @@ -98,18 +98,18 @@ func (s *Settings[C]) Watch() *Settings[C] { } // add all files to the watch list - for file := range s.fileWatch.watchList { + for filePath := range s.fileWatch.watchList { - fileInfo, err := os.Stat(file) + fileInfo, err := os.Stat(filePath) if err != nil { s.errors = append(s.errors, err) continue } if fileInfo.IsDir() { - err = s.fileWatch.watcher.Add(file) + err = s.fileWatch.watcher.Add(filePath) } else { - err = s.fileWatch.watcher.Add(path.Dir(file)) + err = s.fileWatch.watcher.Add(path.Dir(filePath)) } if err != nil { -- GitLab