Skip to content

Commit 4b8d148

Browse files
committedNov 4, 2022
refactor: use new Has fsnotify method for event matching
Signed-off-by: Mark Sagi-Kazar <[email protected]>
1 parent 2e99a57 commit 4b8d148

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed
 

‎viper.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,8 @@ func (v *Viper) WatchConfig() {
463463
// we only care about the config file with the following cases:
464464
// 1 - if the config file was modified or created
465465
// 2 - if the real path to the config file changed (eg: k8s ConfigMap replacement)
466-
const writeOrCreateMask = fsnotify.Write | fsnotify.Create
467466
if (filepath.Clean(event.Name) == configFile &&
468-
event.Op&writeOrCreateMask != 0) ||
467+
(event.Has(fsnotify.Write) || event.Has(fsnotify.Create))) ||
469468
(currentConfigFile != "" && currentConfigFile != realConfigFile) {
470469
realConfigFile = currentConfigFile
471470
err := v.ReadInConfig()
@@ -475,8 +474,7 @@ func (v *Viper) WatchConfig() {
475474
if v.onConfigChange != nil {
476475
v.onConfigChange(event)
477476
}
478-
} else if filepath.Clean(event.Name) == configFile &&
479-
event.Op&fsnotify.Remove != 0 {
477+
} else if filepath.Clean(event.Name) == configFile && event.Has(fsnotify.Remove) {
480478
eventsWG.Done()
481479
return
482480
}

0 commit comments

Comments
 (0)
Please sign in to comment.