Skip to content

Commit

Permalink
refactor: use new Has fsnotify method for event matching
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed Nov 3, 2022
1 parent 673d55e commit 1bcb21f
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions viper.go
Expand Up @@ -463,9 +463,8 @@ func (v *Viper) WatchConfig() {
// we only care about the config file with the following cases:
// 1 - if the config file was modified or created
// 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 &&
event.Op&writeOrCreateMask != 0) ||
(event.Has(fsnotify.Write) || event.Has(fsnotify.Create))) ||
(currentConfigFile != "" && currentConfigFile != realConfigFile) {
realConfigFile = currentConfigFile
err := v.ReadInConfig()
Expand All @@ -475,8 +474,7 @@ func (v *Viper) WatchConfig() {
if v.onConfigChange != nil {
v.onConfigChange(event)
}
} else if filepath.Clean(event.Name) == configFile &&
event.Op&fsnotify.Remove != 0 {
} else if filepath.Clean(event.Name) == configFile && event.Has(fsnotify.Remove) {
eventsWG.Done()
return
}
Expand Down

0 comments on commit 1bcb21f

Please sign in to comment.