Skip to content

Commit c201a61

Browse files
committed
chore: upgraded fsnotify to v1.4.9
1 parent 2bc4b3d commit c201a61

File tree

13 files changed

+115
-66
lines changed

13 files changed

+115
-66
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/docker/go-units v0.4.0 // indirect
1717
github.com/evanphx/json-patch v4.5.0+incompatible
1818
github.com/fortytw2/leaktest v1.3.1-0.20190606143808-d73c753520d9
19-
github.com/fsnotify/fsnotify v0.9.3
19+
github.com/fsnotify/fsnotify v1.4.9
2020
github.com/ghodss/yaml v1.0.0 // indirect
2121
github.com/go-ole/go-ole v1.2.1 // indirect
2222
github.com/gogo/protobuf v1.1.2-0.20181116123445-07eab6a8298c // indirect

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ github.com/fortytw2/leaktest v1.3.1-0.20190606143808-d73c753520d9 h1:tKHw9zBEj0r
4747
github.com/fortytw2/leaktest v1.3.1-0.20190606143808-d73c753520d9/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
4848
github.com/fsnotify/fsnotify v0.9.3 h1:ohbr5HT+EHaq7KpTqPxkowzWw0vTFj25E8HVrVVHNIA=
4949
github.com/fsnotify/fsnotify v0.9.3/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
50+
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
51+
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
5052
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
5153
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
5254
github.com/go-fsnotify/fsnotify v0.0.0-20180321022601-755488143dae h1:PeVNzgTRtWGm6fVic5i21t+n5ptPGCZuMcSPVMyTWjs=
@@ -135,6 +137,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
135137
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
136138
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
137139
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
140+
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
138141
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
139142
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=
140143
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

internal/agent/bulk_inventories_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import (
1919
const maxInventoryDataSize = 3 * 1000 * 1000
2020

2121
var plugin = &delta.PluginInfo{
22-
Source: "metadata/plugin",
23-
Plugin: "metadata",
24-
FileName: "plugin.json",
22+
Source: "metadata/plugin",
23+
Plugin: "metadata",
24+
FileName: "plugin.json",
2525
}
2626

2727
// createDelta creates and stores a delta JSON for a given entity, with a size approximate to the given size

internal/agent/delta/store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func (s *Store) updateLastDeltaSent(entityKey string, dRaw *inventoryapi.RawDelt
406406
// Send again? This is a no-op, set last sent id to one previous.
407407
dslog.WithFields(logrus.Fields{"sendNextID": id, "plugin": p}).
408408
Debug("Requesting to update last delta sent to identical value.")
409-
p.setLastSentID(entityKey, id - 1)
409+
p.setLastSentID(entityKey, id-1)
410410
}
411411
} else if id > p.lastSentID(entityKey) {
412412
p.setLastSentID(entityKey, id)
@@ -417,7 +417,7 @@ func (s *Store) updateLastDeltaSent(entityKey string, dRaw *inventoryapi.RawDelt
417417

418418
func (s *Store) reconciliateWithBackend(pi *PluginInfo, entityKey string, resultHint *inventoryapi.DeltaState) {
419419
_ = s.clearPluginDeltaStore(pi, entityKey)
420-
pi.setLastSentID(entityKey, resultHint.SendNextID - 1)
420+
pi.setLastSentID(entityKey, resultHint.SendNextID-1)
421421
pi.setDeltaID(entityKey, resultHint.LastStoredID)
422422
}
423423

internal/agent/delta/store_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ func (s *DeltaUtilsCoreSuite) TestCompactStoreTrimSentDelta(c *C) {
725725
const eKey = "entity:ID"
726726

727727
ds := s.SetupSavedState(c)
728-
ds.plugins["metadata/plugin"].setLastSentID(eKey,2)
728+
ds.plugins["metadata/plugin"].setLastSentID(eKey, 2)
729729
err := ds.archivePlugin(ds.plugins["metadata/plugin"], eKey)
730730
c.Check(err, IsNil)
731731
size, err := ds.StorageSize(ds.CacheDir)
@@ -801,8 +801,8 @@ func (s *DeltaUtilsCoreSuite) TestDeltaFileCorrupt(c *C) {
801801

802802
secondPlugin := newPluginInfo("metadata", "plugin.json")
803803
// break on purpose, so read should fail
804-
secondPlugin.Source = "metadata/plugin2"
805-
secondPlugin.Plugin = "metadata2"
804+
secondPlugin.Source = "metadata/plugin2"
805+
secondPlugin.Plugin = "metadata2"
806806

807807
srcFile2 := ds.SourceFilePath(secondPlugin, eKey)
808808
err = os.MkdirAll(filepath.Dir(srcFile2), 0755)

internal/plugins/linux/dpkg.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (self *DpkgPlugin) Run() {
136136
return
137137
}
138138

139-
err = watcher.WatchFlags("/var/lib/dpkg/lock", FSN_CLOSE_WRITE)
139+
err = watcher.Add("/var/lib/dpkg/lock")
140140
if err != nil {
141141
dpkglog.WithError(err).Error("can't setup trigger file watcher for dpkg")
142142
self.Unregister()
@@ -147,14 +147,16 @@ func (self *DpkgPlugin) Run() {
147147
ticker := time.NewTicker(1)
148148
for {
149149
select {
150-
case _, ok := <-watcher.Event:
150+
case event, ok := <-watcher.Events:
151151
if ok {
152-
counter = counter + 1
153-
if counter > 1 {
154-
dpkglog.WithFields(logrus.Fields{
155-
"frequency": self.frequency,
156-
"counter": counter,
157-
}).Debug("dpkg plugin oversampling.")
152+
if event.Op&fsnotify.Write == fsnotify.Write {
153+
counter = counter + 1
154+
if counter > 1 {
155+
dpkglog.WithFields(logrus.Fields{
156+
"frequency": self.frequency,
157+
"counter": counter,
158+
}).Debug("dpkg plugin oversampling.")
159+
}
158160
}
159161
} else {
160162
dpkglog.Debug("dpkg lock watcher closed.")

internal/plugins/linux/rpm.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ func (p *rpmPlugin) Run() {
135135
return
136136
}
137137

138-
err = watcher.WatchFlags("/var/lib/rpm/.rpm.lock", FSN_CLOSE_WRITE)
138+
err = watcher.Add("/var/lib/rpm/.rpm.lock")
139139
if err != nil {
140140
// Some old distros, like SLES 11, do not provide .rpm.lock file, but the same
141141
// effect can be achieved by listening some standard files from the RPM database
142-
err = watcher.WatchFlags("/var/lib/rpm/Installtid", FSN_CLOSE_WRITE)
142+
err = watcher.Add("/var/lib/rpm/Installtid")
143143
if err != nil {
144144
rpmlog.WithError(err).Error("can't setup trigger file watcher for rpm")
145145
p.Unregister()
@@ -151,14 +151,16 @@ func (p *rpmPlugin) Run() {
151151
ticker := time.NewTicker(1)
152152
for {
153153
select {
154-
case _, ok := <-watcher.Event:
154+
case event, ok := <-watcher.Events:
155155
if ok {
156-
counter = counter + 1
157-
if counter > 1 {
158-
rpmlog.WithFields(logrus.Fields{
159-
"frequency": p.frequency,
160-
"counter": counter,
161-
}).Debug("rpm plugin oversampling.")
156+
if event.Op&fsnotify.Write == fsnotify.Write {
157+
counter = counter + 1
158+
if counter > 1 {
159+
rpmlog.WithFields(logrus.Fields{
160+
"frequency": p.frequency,
161+
"counter": counter,
162+
}).Debug("rpm plugin oversampling.")
163+
}
162164
}
163165
} else {
164166
rpmlog.Debug("rpm lock watcher closed.")

internal/plugins/linux/sysctl_subscriber.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewSysctlSubscriberMonitor(id ids.PluginID, ctx agent.AgentContext) (*Sysct
3434
return nil, errors.Wrap(err, "cannot create sys watcher")
3535
}
3636

37-
err = watcher.WatchFlags(sysPoller.procSysDir, fsnotify.FSN_MODIFY)
37+
err = watcher.Add(sysPoller.procSysDir)
3838
if err != nil {
3939
return nil, errors.Wrap(err, "cannot watch on sys filesystem")
4040
}
@@ -71,19 +71,25 @@ func (p *SysctlSubscriberPlugin) Run() {
7171
ticker.Stop()
7272
ticker = time.NewTicker(p.frequency)
7373

74-
case e := <-p.watcher.Event:
75-
needsFlush = true
76-
output, err := ioutil.ReadFile(e.Name)
77-
if err != nil {
78-
sclog.WithField("file", e.Name).Debug("Cannot read sys file.")
79-
} else {
80-
deltas = append(deltas, p.newSysctlItem(e.Name, output))
74+
case event, ok := <-p.watcher.Events:
75+
if !ok {
76+
continue
77+
}
78+
79+
if event.Op&fsnotify.Write == fsnotify.Write {
80+
needsFlush = true
81+
output, err := ioutil.ReadFile(event.Name)
82+
if err != nil {
83+
sclog.WithField("file", event.Name).Debug("Cannot read sys file.")
84+
} else {
85+
deltas = append(deltas, p.newSysctlItem(event.Name, output))
86+
}
8187
}
8288
}
8389
}
8490
}
8591

8692
// deprecated, just for testing purposes
87-
func (p *SysctlSubscriberPlugin) EventsCh() chan *fsnotify.FileEvent {
88-
return p.watcher.Event
93+
func (p *SysctlSubscriberPlugin) EventsCh() chan fsnotify.Event {
94+
return p.watcher.Events
8995
}

internal/plugins/linux/users.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (self *UsersPlugin) Run() {
9797
return
9898
}
9999

100-
err = watcher.WatchFlags("/var/run/utmp", fsnotify.FSN_MODIFY)
100+
err = watcher.Add("/var/run/utmp")
101101
if err != nil {
102102
usrlog.WithError(err).Error("can't setup trigger file watcher for users")
103103
self.Unregister()
@@ -108,8 +108,12 @@ func (self *UsersPlugin) Run() {
108108

109109
for {
110110
select {
111-
case <-watcher.Event:
112-
needsFlush = true
111+
case event, ok := <-watcher.Events:
112+
if ok {
113+
if event.Op&fsnotify.Write == fsnotify.Write {
114+
needsFlush = true
115+
}
116+
}
113117
case <-refreshTimer.C:
114118
{
115119
refreshTimer.Reset(self.frequency)

pkg/integrations/v4/logs/cfg_watcher.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (ccw *ConfigChangesWatcher) Watch(ctx ctx2.Context, changes chan<- struct{}
3737
return
3838
}
3939
ccw.logger.Debugf("adding path to watching %v", ccw.path)
40-
if err := ccw.watcher.Watch(ccw.path); err != nil {
40+
if err := ccw.watcher.Add(ccw.path); err != nil {
4141
ccw.logger.WithError(err).Warn("cant watch for file changes in folder")
4242
return
4343
}
@@ -55,9 +55,9 @@ func (ccw *ConfigChangesWatcher) watchForChanges(ctx ctx2.Context, changes chan<
5555
ccw.logger.Debug("Watching for logging config file changes.")
5656
for {
5757
select {
58-
case event := <-ccw.watcher.Event:
59-
ccw.handleFileEvent(event, changes)
60-
case err := <-ccw.watcher.Error:
58+
case event := <-ccw.watcher.Events:
59+
ccw.handleFileEvent(&event, changes)
60+
case err := <-ccw.watcher.Errors:
6161
ccw.logger.WithError(err).Debug("Error occurred while watching for logging config file changes.")
6262
case <-ctx.Done():
6363
ccw.logger.Debug("Stopping logging config changes watcher.")
@@ -69,7 +69,7 @@ func (ccw *ConfigChangesWatcher) watchForChanges(ctx ctx2.Context, changes chan<
6969
}
7070
}
7171

72-
func (ccw *ConfigChangesWatcher) handleFileEvent(event *fsnotify.FileEvent, signalReload chan<- struct{}) {
72+
func (ccw *ConfigChangesWatcher) handleFileEvent(event *fsnotify.Event, signalReload chan<- struct{}) {
7373
helog := ccw.logger.WithField("function", "handleFileEvent")
7474

7575
if event == nil {
@@ -81,9 +81,23 @@ func (ccw *ConfigChangesWatcher) handleFileEvent(event *fsnotify.FileEvent, sign
8181
WithField("file_name", event.Name)
8282
elog.Debug("Received File event.")
8383

84-
isDelete := event.IsDelete() || event.IsRename()
85-
isCreate := event.IsCreate()
86-
isWrite := isCreate || event.IsModify()
84+
var eDelete, eCreate, eWrite, eRename bool
85+
if event.Op&fsnotify.Write == fsnotify.Write {
86+
eWrite = true
87+
}
88+
if event.Op&fsnotify.Remove == fsnotify.Remove {
89+
eDelete = true
90+
}
91+
if event.Op&fsnotify.Create == fsnotify.Create {
92+
eCreate = true
93+
}
94+
if event.Op&fsnotify.Rename == fsnotify.Rename {
95+
eRename = true
96+
}
97+
98+
isDelete := eDelete || eRename
99+
isCreate := eCreate
100+
isWrite := isCreate || eWrite
87101
if !isDelete && !isWrite {
88102
elog.Debug("Ignoring File event.")
89103
return

0 commit comments

Comments
 (0)