Skip to content

Commit 0864357

Browse files
committed
Merge branch 'master' into feat/list-k-v-map
2 parents f5ae99f + 54b7c24 commit 0864357

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

os/gcfg/gcfg_adapter_file.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func (a *AdapterFile) getJson(fileNameOrPath ...string) (configJson *gjson.Json,
297297
// Add monitor for this configuration file,
298298
// any changes of this file will refresh its cache in the Config object.
299299
if filePath != "" && !gres.Contains(filePath) {
300-
_, err = gfsnotify.Add(filePath, func(event *gfsnotify.Event) {
300+
_, err := gfsnotify.Add(filePath, func(event *gfsnotify.Event) {
301301
a.jsonMap.Remove(usedFileNameOrPath)
302302
if event.IsWrite() || event.IsRemove() || event.IsCreate() || event.IsRename() || event.IsChmod() {
303303
fileType := gfile.ExtName(usedFileNameOrPath)
@@ -316,9 +316,10 @@ func (a *AdapterFile) getJson(fileNameOrPath ...string) (configJson *gjson.Json,
316316
}
317317
a.notifyWatchers(adapterCtx.Ctx)
318318
}
319+
_ = event.Watcher.Remove(filePath)
319320
})
320321
if err != nil {
321-
return nil
322+
intlog.Errorf(context.TODO(), "failed listen config file event[%s]: %v", filePath, err)
322323
}
323324
}
324325
return configJson

os/gfsnotify/gfsnotify_watcher.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import (
2020
// The parameter `path` can be either a file or a directory path.
2121
// The optional parameter `recursive` specifies whether monitoring the `path` recursively,
2222
// which is true in default.
23-
func (w *Watcher) Add(
24-
path string, callbackFunc func(event *Event), option ...WatchOption,
23+
func (w *Watcher) Add(path string, callbackFunc func(event *Event), option ...WatchOption,
2524
) (callback *Callback, err error) {
2625
return w.AddOnce("", path, callbackFunc, option...)
2726
}
@@ -35,8 +34,7 @@ func (w *Watcher) Add(
3534
// The parameter `path` can be either a file or a directory path.
3635
// The optional parameter `recursive` specifies whether monitoring the `path` recursively,
3736
// which is true in default.
38-
func (w *Watcher) AddOnce(
39-
name, path string, callbackFunc func(event *Event), option ...WatchOption,
37+
func (w *Watcher) AddOnce(name, path string, callbackFunc func(event *Event), option ...WatchOption,
4038
) (callback *Callback, err error) {
4139
var watchOption = w.getWatchOption(option...)
4240
w.nameSet.AddIfNotExistFuncLock(name, func() bool {
@@ -89,8 +87,7 @@ func (w *Watcher) getWatchOption(option ...WatchOption) WatchOption {
8987

9088
// addWithCallbackFunc adds the path to underlying monitor, creates and returns a callback object.
9189
// Very note that if it calls multiple times with the same `path`, the latest one will overwrite the previous one.
92-
func (w *Watcher) addWithCallbackFunc(
93-
name, path string, callbackFunc func(event *Event), option ...WatchOption,
90+
func (w *Watcher) addWithCallbackFunc(name, path string, callbackFunc func(event *Event), option ...WatchOption,
9491
) (callback *Callback, err error) {
9592
var watchOption = w.getWatchOption(option...)
9693
// Check and convert the given path to absolute path.

0 commit comments

Comments
 (0)