mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
refactor: use new Has fsnotify method for event matching
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
parent
2e99a57324
commit
4b8d14881e
1 changed files with 2 additions and 4 deletions
6
viper.go
6
viper.go
|
@ -463,9 +463,8 @@ func (v *Viper) WatchConfig() {
|
||||||
// we only care about the config file with the following cases:
|
// we only care about the config file with the following cases:
|
||||||
// 1 - if the config file was modified or created
|
// 1 - if the config file was modified or created
|
||||||
// 2 - if the real path to the config file changed (eg: k8s ConfigMap replacement)
|
// 2 - if the real path to the config file changed (eg: k8s ConfigMap replacement)
|
||||||
const writeOrCreateMask = fsnotify.Write | fsnotify.Create
|
|
||||||
if (filepath.Clean(event.Name) == configFile &&
|
if (filepath.Clean(event.Name) == configFile &&
|
||||||
event.Op&writeOrCreateMask != 0) ||
|
(event.Has(fsnotify.Write) || event.Has(fsnotify.Create))) ||
|
||||||
(currentConfigFile != "" && currentConfigFile != realConfigFile) {
|
(currentConfigFile != "" && currentConfigFile != realConfigFile) {
|
||||||
realConfigFile = currentConfigFile
|
realConfigFile = currentConfigFile
|
||||||
err := v.ReadInConfig()
|
err := v.ReadInConfig()
|
||||||
|
@ -475,8 +474,7 @@ func (v *Viper) WatchConfig() {
|
||||||
if v.onConfigChange != nil {
|
if v.onConfigChange != nil {
|
||||||
v.onConfigChange(event)
|
v.onConfigChange(event)
|
||||||
}
|
}
|
||||||
} else if filepath.Clean(event.Name) == configFile &&
|
} else if filepath.Clean(event.Name) == configFile && event.Has(fsnotify.Remove) {
|
||||||
event.Op&fsnotify.Remove != 0 {
|
|
||||||
eventsWG.Done()
|
eventsWG.Done()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue