Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions os/gcfg/gcfg_adapter_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (a *AdapterFile) getJson(fileNameOrPath ...string) (configJson *gjson.Json,
// Add monitor for this configuration file,
// any changes of this file will refresh its cache in the Config object.
if filePath != "" && !gres.Contains(filePath) {
_, err = gfsnotify.Add(filePath, func(event *gfsnotify.Event) {
_, err := gfsnotify.Add(filePath, func(event *gfsnotify.Event) {
a.jsonMap.Remove(usedFileNameOrPath)
if event.IsWrite() || event.IsRemove() || event.IsCreate() || event.IsRename() || event.IsChmod() {
fileType := gfile.ExtName(usedFileNameOrPath)
Expand All @@ -316,9 +316,10 @@ func (a *AdapterFile) getJson(fileNameOrPath ...string) (configJson *gjson.Json,
}
a.notifyWatchers(adapterCtx.Ctx)
}
_ = event.Watcher.Remove(filePath)
})
if err != nil {
return nil
intlog.Errorf(context.TODO(), "failed listen config file event[%s]: %v", filePath, err)
}
}
return configJson
Expand Down
9 changes: 3 additions & 6 deletions os/gfsnotify/gfsnotify_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import (
// The parameter `path` can be either a file or a directory path.
// The optional parameter `recursive` specifies whether monitoring the `path` recursively,
// which is true in default.
func (w *Watcher) Add(
path string, callbackFunc func(event *Event), option ...WatchOption,
func (w *Watcher) Add(path string, callbackFunc func(event *Event), option ...WatchOption,
) (callback *Callback, err error) {
return w.AddOnce("", path, callbackFunc, option...)
}
Expand All @@ -35,8 +34,7 @@ func (w *Watcher) Add(
// The parameter `path` can be either a file or a directory path.
// The optional parameter `recursive` specifies whether monitoring the `path` recursively,
// which is true in default.
func (w *Watcher) AddOnce(
name, path string, callbackFunc func(event *Event), option ...WatchOption,
func (w *Watcher) AddOnce(name, path string, callbackFunc func(event *Event), option ...WatchOption,
) (callback *Callback, err error) {
var watchOption = w.getWatchOption(option...)
w.nameSet.AddIfNotExistFuncLock(name, func() bool {
Expand Down Expand Up @@ -89,8 +87,7 @@ func (w *Watcher) getWatchOption(option ...WatchOption) WatchOption {

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