Skip to content

Commit 58334aa

Browse files
committed
Fix file modified returns incorrect PID (#6)
- The PID is from os.WriteFile. Moving the file creation above listener start fixes the PID issue
1 parent 82acc34 commit 58334aa

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

fanotify_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ func TestWithCapSysAdmFanotifyFileModified(t *testing.T) {
104104
assert.Nil(t, err)
105105
assert.NotNil(t, l)
106106
watchDir := t.TempDir()
107+
107108
t.Logf("Watch Directory: %s", watchDir)
108-
action := FileModified
109-
l.AddWatch(watchDir, action)
110-
go l.Start()
111-
defer l.Stop()
112-
// generate event
113109
data := []byte("test data...")
114110
testFile := fmt.Sprintf("%s/test.dat", watchDir)
115111
err = os.WriteFile(testFile, data, 0666)
116112
assert.Nil(t, err)
117113
t.Logf("Test file created %s", testFile)
114+
action := FileModified
115+
l.AddWatch(watchDir, action)
116+
go l.Start()
117+
defer l.Stop()
118118
pid, err := modifyFile(testFile)
119119
assert.Nil(t, err)
120120
select {

0 commit comments

Comments
 (0)