Skip to content

Commit

Permalink
fix(dynamic_conf) fix watch
Browse files Browse the repository at this point in the history
fix(dynamic_conf) fix watch

fix(dynamic_conf) fix watch

fix(dynamic_conf) fix watch

fix(dynamic_conf) fix watch
  • Loading branch information
jaronnie committed Dec 19, 2024
1 parent 07bad4b commit 776d556
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions dynamic_conf/fsnotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dynamic_conf

import (
"os"
"path/filepath"

"github.com/fsnotify/fsnotify"
"github.com/zeromicro/go-zero/core/configcenter/subscriber"
Expand Down Expand Up @@ -35,7 +36,8 @@ func (lf *FsNotify) AddListener(listener func()) error {
if !ok {
return
}
if event.Has(fsnotify.Write) {
logx.Infof("%s %s", event.Name, event.Op)
if event.Has(fsnotify.Write) || event.Has(fsnotify.Rename) {
listener()
}
case err, ok := <-lf.Watcher.Errors:
Expand All @@ -47,7 +49,8 @@ func (lf *FsNotify) AddListener(listener func()) error {
}
}()

if err := lf.Watcher.Add(lf.Path); err != nil {
// see: https://github.com/fsnotify/fsnotify/issues/363
if err := lf.Watcher.Add(filepath.Dir(lf.Path)); err != nil {
return err
}
return nil
Expand Down

0 comments on commit 776d556

Please sign in to comment.