New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing Remove Event when file handle open before for Linux #194
Comments
What is happening here is that Linux's inotify actually delivers two notifications when a file is deleted. It first sends Here is a func TestInotifyDeleteOpenFile(t *testing.T) {
testDir := tempMkdir(t)
defer os.RemoveAll(testDir)
testFile := filepath.Join(testDir, "testfile")
handle, err := os.Create(testFile)
if err != nil {
t.Fatalf("Create failed: %v", err)
}
w, err := NewWatcher()
if err != nil {
t.Fatalf("Failed to create watcher: %v", err)
}
defer w.Close()
err = w.Add(testFile)
if err != nil {
t.Fatalf("Failed to add watch for %s: %v", testFile, err)
}
err = os.Remove(testFile)
if err != nil {
t.Fatalf("Failed to remove %s: %v", testFile, err)
}
var event Event
func() {
defer handle.Close()
select {
case event = <-w.Events:
case <-time.After(100 * time.Millisecond):
t.Fatalf("Expected event not delivered")
}
}()
if event.Op != Remove {
t.Fatalf("Expected event type %s, got: %v", Remove, event.Op)
}
w.Close()
// Wait for the close to complete.
time.Sleep(50 * time.Millisecond)
isWatcherReallyClosed(t, w)
} I can see a few options for dealing with this, none of them perfect:
|
since its a library, I will prefer both event should be delivered to clients. This will keep policies out of this layer. |
Im creating log forwarder and try to using fsnotify. Workaround this by getting stat every iteration =( |
To include fsnotify/fsnotify#260 (fix for fsnotify/fsnotify#194). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
To include fsnotify/fsnotify#260 (fix for fsnotify/fsnotify#194). Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Thanks for the report. #260 should resolve this issue. |
Before reporting an issue, please ensure you are using the latest release of fsnotify.
Which operating system (GOOS) and version are you using?
Linux: lsb_release -a
macOS: sw_vers
Windows: systeminfo | findstr /B /C:OS
Linux:
LSB Version: :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.8 (Final)
Release: 5.8
Codename: Final
Please describe the issue that occurred.
Missing Remove Event when got file handle already open before. See the sample.
And I review the fsnotify code(fsnotify/inotify.go/func newEvent) found that unix.IN_ATTRIB was catched then e.Op was set to Chmod when
rm -f $filename;echo >$filename
done.After that the event was ignored by "func ignoreLinux"
For this reason, I must watch the directory to walk around.
Are you able to reproduce the issue? Please provide steps to reproduce and a code sample if possible.
The text was updated successfully, but these errors were encountered: