mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
fsnotify: use event.Has instead of "event.Op&h == h"
This commit is contained in:
parent
3fee9d2735
commit
2ce7a81169
@ -257,10 +257,7 @@ func (o *Options) initWatcher() error {
|
||||
}
|
||||
|
||||
func (o *Options) eventHandler(ent fsnotify.Event) {
|
||||
eventOpIs := func(Op fsnotify.Op) bool {
|
||||
return ent.Op&Op == Op
|
||||
}
|
||||
if eventOpIs(fsnotify.Write) || eventOpIs(fsnotify.Rename) {
|
||||
if ent.Has(fsnotify.Write) || ent.Has(fsnotify.Rename) {
|
||||
// error out when ConfigFile is updated
|
||||
o.errCh <- fmt.Errorf("content of the proxy server's configuration file was updated")
|
||||
return
|
||||
|
@ -73,12 +73,12 @@ func (w *Watcher) Start(stopCh <-chan struct{}) error {
|
||||
select {
|
||||
case event := <-fsWatcher.Events:
|
||||
//TODO: Handle errors by taking corrective measures
|
||||
if event.Op&fsnotify.Create == fsnotify.Create {
|
||||
if event.Has(fsnotify.Create) {
|
||||
err := w.handleCreateEvent(event)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Error when handling create event", "event", event)
|
||||
}
|
||||
} else if event.Op&fsnotify.Remove == fsnotify.Remove {
|
||||
} else if event.Has(fsnotify.Remove) {
|
||||
w.handleDeleteEvent(event)
|
||||
}
|
||||
continue
|
||||
|
@ -169,7 +169,7 @@ func (prober *flexVolumeProber) handleWatchEvent(event fsnotify.Event) error {
|
||||
if eventPathAbs == pluginDirAbs {
|
||||
// If the Flexvolume plugin directory is removed, need to recreate it
|
||||
// in order to keep it under watch.
|
||||
if eventOpIs(event, fsnotify.Remove) {
|
||||
if event.Has(fsnotify.Remove) {
|
||||
if err := prober.createPluginDir(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -181,7 +181,7 @@ func (prober *flexVolumeProber) handleWatchEvent(event fsnotify.Event) error {
|
||||
}
|
||||
|
||||
// watch newly added subdirectories inside a driver directory
|
||||
if eventOpIs(event, fsnotify.Create) {
|
||||
if event.Has(fsnotify.Create) {
|
||||
if err := prober.addWatchRecursive(eventPathAbs); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -197,7 +197,7 @@ func (prober *flexVolumeProber) handleWatchEvent(event fsnotify.Event) error {
|
||||
driverDirName := strings.Split(eventRelPathToPluginDir, string(os.PathSeparator))[0]
|
||||
driverDirAbs := filepath.Join(pluginDirAbs, driverDirName)
|
||||
// executable is removed, will trigger ProbeRemove event
|
||||
if eventOpIs(event, fsnotify.Remove) && (eventRelPathToPluginDir == getExecutablePathRel(driverDirName) || parentPathAbs == pluginDirAbs) {
|
||||
if event.Has(fsnotify.Remove) && (eventRelPathToPluginDir == getExecutablePathRel(driverDirName) || parentPathAbs == pluginDirAbs) {
|
||||
prober.updateEventsMap(driverDirAbs, volume.ProbeRemove)
|
||||
} else {
|
||||
prober.updateEventsMap(driverDirAbs, volume.ProbeAddOrUpdate)
|
||||
@ -281,7 +281,3 @@ func (prober *flexVolumeProber) testAndSetProbeAllNeeded(newval bool) (oldval bo
|
||||
oldval, prober.probeAllNeeded = prober.probeAllNeeded, newval
|
||||
return
|
||||
}
|
||||
|
||||
func eventOpIs(event fsnotify.Event, op fsnotify.Op) bool {
|
||||
return event.Op&op == op
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ func (c *DynamicFileCAContent) watchCAFile(stopCh <-chan struct{}) error {
|
||||
func (c *DynamicFileCAContent) handleWatchEvent(e fsnotify.Event, w *fsnotify.Watcher) error {
|
||||
// This should be executed after restarting the watch (if applicable) to ensure no file event will be missing.
|
||||
defer c.queue.Add(workItemKey)
|
||||
if e.Op&(fsnotify.Remove|fsnotify.Rename) == 0 {
|
||||
if !e.Has(fsnotify.Remove) && !e.Has(fsnotify.Rename) {
|
||||
return nil
|
||||
}
|
||||
if err := w.Remove(c.filename); err != nil {
|
||||
|
@ -185,7 +185,7 @@ func (c *DynamicCertKeyPairContent) watchCertKeyFile(stopCh <-chan struct{}) err
|
||||
func (c *DynamicCertKeyPairContent) handleWatchEvent(e fsnotify.Event, w *fsnotify.Watcher) error {
|
||||
// This should be executed after restarting the watch (if applicable) to ensure no file event will be missing.
|
||||
defer c.queue.Add(workItemKey)
|
||||
if e.Op&(fsnotify.Remove|fsnotify.Rename) == 0 {
|
||||
if !e.Has(fsnotify.Remove) && !e.Has(fsnotify.Rename) {
|
||||
return nil
|
||||
}
|
||||
if err := w.Remove(e.Name); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user