4 // NNCP -- Node to Node copy, utilities for store-and-forward data exchange
5 // Copyright (C) 2016-2024 Sergey Matveev <stargrave@stargrave.org>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, version 3 of the License.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
25 "github.com/fsnotify/fsnotify"
28 type DirWatcher struct {
34 func (ctx *Ctx) NewDirWatcher(dir string, d time.Duration) (*DirWatcher, error) {
35 w, err := fsnotify.NewWatcher()
50 C: make(chan struct{}),
51 isDead: make(chan struct{}),
54 ticker := time.NewTicker(d)
59 case err := <-w.Errors:
60 ctx.LogE("dir-watch", LEs{{"Dir", dir}}, err, func(les LEs) string {
61 return "fsnotify error: " + err.Error()
64 ctx.LogD("dir-watch-event", LEs{{"Dir", dir}}, func(les LEs) string {
65 return fmt.Sprintf("fsnotify event: %v", e)
67 if e.Op&(fsnotify.Create|fsnotify.Rename) > 0 {
86 func (dw *DirWatcher) Close() {