Skip to content

Commit

Permalink
Make fsnotify event more readable.
Browse files Browse the repository at this point in the history
Signed-off-by: yanggang <gang.yang@daocloud.io>
  • Loading branch information
yanggang authored and jrajahalme committed Nov 28, 2022
1 parent e6fb48a commit 5b573c3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions pkg/clustermesh/config.go
Expand Up @@ -96,12 +96,12 @@ func (cdw *configDirectoryWatcher) watch() error {
name := filepath.Base(event.Name)
log.WithField(fieldClusterName, name).Debugf("Received fsnotify event: %+v", event)
switch {
case event.Op&fsnotify.Create == fsnotify.Create,
event.Op&fsnotify.Write == fsnotify.Write,
event.Op&fsnotify.Chmod == fsnotify.Chmod:
case event.Has(fsnotify.Create),
event.Has(fsnotify.Write),
event.Has(fsnotify.Chmod):
cdw.handleAddedFile(name, event.Name)
case event.Op&fsnotify.Remove == fsnotify.Remove,
event.Op&fsnotify.Rename == fsnotify.Rename:
case event.Has(fsnotify.Remove),
event.Has(fsnotify.Rename):
cdw.lifecycle.remove(name)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/datapath/loader/cache.go
Expand Up @@ -354,7 +354,7 @@ func (o *objectCache) watchTemplatesDirectory(ctx context.Context) error {
if !open {
break
}
if event.Op&fsnotify.Remove == fsnotify.Remove {
if event.Has(fsnotify.Remove) {
log.WithField(logfields.Path, event.Name).Debug("Detected template removal")
templateHash := filepath.Base(filepath.Dir(event.Name))
o.delete(templateHash)
Expand Down
8 changes: 4 additions & 4 deletions pkg/fswatcher/fswatcher.go
Expand Up @@ -216,10 +216,10 @@ func (w *Watcher) loop() {
scopedLog.Debug("Received fsnotify event")

eventPath := event.Name
removed := event.Op&fsnotify.Remove == fsnotify.Remove
renamed := event.Op&fsnotify.Rename == fsnotify.Rename
created := event.Op&fsnotify.Create == fsnotify.Create
written := event.Op&fsnotify.Write == fsnotify.Write
removed := event.Has(fsnotify.Remove)
renamed := event.Has(fsnotify.Rename)
created := event.Has(fsnotify.Create)
written := event.Has(fsnotify.Write)

// If a the eventPath has been removed or renamed, it can no longer
// be a valid watchPath. This is needed such that each trackedPath
Expand Down
10 changes: 5 additions & 5 deletions pkg/ipmasq/ipmasq.go
Expand Up @@ -145,11 +145,11 @@ func (a *IPMasqAgent) Start() {
log.Debugf("Received fsnotify event: %+v", event)

switch {
case event.Op&fsnotify.Create == fsnotify.Create,
event.Op&fsnotify.Write == fsnotify.Write,
event.Op&fsnotify.Chmod == fsnotify.Chmod,
event.Op&fsnotify.Remove == fsnotify.Remove,
event.Op&fsnotify.Rename == fsnotify.Rename:
case event.Has(fsnotify.Create),
event.Has(fsnotify.Write),
event.Has(fsnotify.Chmod),
event.Has(fsnotify.Remove),
event.Has(fsnotify.Rename):
if err := a.Update(); err != nil {
log.WithError(err).Warn("Failed to update")
}
Expand Down

0 comments on commit 5b573c3

Please sign in to comment.