diff options
| author | RanXom <saiyedshizain@gmail.com> | 2026-07-14 12:35:51 +0530 |
|---|---|---|
| committer | RanXom <saiyedshizain@gmail.com> | 2026-07-14 12:35:51 +0530 |
| commit | d2c0c970f690d52ee3675f377a5eebc22f84afab (patch) | |
| tree | 100d08c4ac01c98f70801c633aa2a95690cc1592 /internal/watcher/fsnotify.go | |
| parent | bd0b89ab49806b976eb0d50dd6f79afdec8b7d11 (diff) | |
| download | galleryd-d2c0c970f690d52ee3675f377a5eebc22f84afab.tar.xz galleryd-d2c0c970f690d52ee3675f377a5eebc22f84afab.zip | |
feat(watcher): watch newly created directories
Diffstat (limited to 'internal/watcher/fsnotify.go')
| -rw-r--r-- | internal/watcher/fsnotify.go | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/internal/watcher/fsnotify.go b/internal/watcher/fsnotify.go index e051c52..7251907 100644 --- a/internal/watcher/fsnotify.go +++ b/internal/watcher/fsnotify.go @@ -3,9 +3,8 @@ package watcher import ( "context" "fmt" - "io/fs" "log" - "path/filepath" + "os" "github.com/fsnotify/fsnotify" ) @@ -24,17 +23,7 @@ func (w *Watcher) Run(ctx context.Context) error { }() for _, root := range w.config.Roots { - if err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error { - if err != nil { - return err - } - - if !d.IsDir() { - return nil - } - - return fswatcher.Add(path) - }); err != nil { + if err := watchTree(fswatcher, root); err != nil { return err } } @@ -51,6 +40,23 @@ func (w *Watcher) Run(ctx context.Context) error { log.Printf("watcher: %v %s", event.Op, event.Name) + if !event.Has(fsnotify.Create) { + continue + } + + info, err := os.Stat(event.Name) + if err != nil { + continue + } + + if !info.IsDir() { + continue + } + + if err := watchTree(fswatcher, event.Name); err != nil { + log.Printf("watch new directory: %v", err) + } + case err, ok := <-fswatcher.Errors: if !ok { return nil |