Skip to content
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 events: Not getting any event for the recreated directory #190

Open
vivek-bansal-VB opened this issue Oct 4, 2020 · 10 comments
Open
Labels

Comments

@vivek-bansal-VB
Copy link

I have set a watch on directory /home/mydir and created a subdirectory (tmp) under it. I dropped some files in directory /home/mydir/tmp and I got the file create events. Then I deleted the directory (/home/mydir/tmp) and recreated it. Again I dropped some files in the directory (/home/mydir/tmp), but this time I am not getting any events in this directory. Seems a probable bug. Any help is much appreciated.

@rjeczalik
Copy link
Owner

Could you please share some reproducer? Go snippet to show how you set watches and some example bash commands how you create temp dir and do all these operations. It would be greatly helpful.

@vivek-bansal-VB
Copy link
Author

vivek-bansal-VB commented Oct 5, 2020

`func main() {
WatchFS("/home/mydir")
}

func WatchFS(rootDir string) {
events := make(chan notify.EventInfo, 100)
setupWatch(rootDir, events)
handleFSEventsInfinite(events)
notify.Stop(events)
}

func setupWatch(path string, events chan notify.EventInfo) error {
if err := notify.Watch(path, events, notify.All, notify.Create, notify.InCreate); err != nil {
fmt.Errorf("failed to setup watch on %q : %v.", path, err)
return err
}
return nil
}

func handleFSEventsInfinite(events chan notify.EventInfo) {
for {
ei := <-events
switch event := ei.Event(); event {
case notify.Create, notify.InCreate:
path := ei.Path()
fi, err := os.Stat(path)
if err != nil {
break
}
if fi.IsDir() {
setupWatch(path, events)
} else {
log.Infof("event is a file create event on file: %q", path)
}
default:
log.Infof("Got non-create event %q", event)
}
}
}`

@vivek-bansal-VB
Copy link
Author

vivek-bansal-VB commented Oct 5, 2020

Below is the shell script which I used to run the commands:
sudo mkdir /home/mydir/tmp
cd /home/mydir/tmp
touch a.txt
cd ..
sudo rm -rf tmp
sudo mkdir /home/mydir/tmp
touch b.txt

@vivek-bansal-VB
Copy link
Author

Output of the above script:
event is a directory create event: "/home/mydir/tmp"
event is a directory create event: "/home/mydir/tmp"
event is a directory create event: "/home/mydir/tmp"
event is a file create event on file: "/home/mydir/tmp/a.txt"
event is a file create event on file: "/home/mydir/tmp/a.txt"
Got non-create event "notify.Remove"
Got non-create event "notify.Remove"
Got non-create event "notify.Remove"
Got non-create event "notify.Remove"
Got non-create event "notify.Remove"
event is a directory create event: "/home/mydir/tmp"
event is a directory create event: "/home/mydir/tmp"
event is a directory create event: "/home/mydir/tmp"
event is a directory create event: "/home/mydir/tmp"

@vivek-bansal-VB
Copy link
Author

As you can see, there is no event generated for file /home/mydir/tmp/b.txt

@vivek-bansal-VB
Copy link
Author

I checked this package: https://github.com/fsnotify/fsnotify and it seems to be working fine even when the directory with the same name is recreated.

@rjeczalik rjeczalik added the bug label Nov 4, 2020
@rjeczalik
Copy link
Owner

@vivek-bansal-VB Thanks for the repro! Since I don't have access to macOS nowadays, someone else would need to troubleshoot it.

Out of curiosity, does it reproduce when you build with kqueue instead of FSEvents? go build -tags kqueue ...

@vivek-bansal-VB
Copy link
Author

@rjeczalik Yes I tried with -tags kqueue and the same issue is there as well.

@vivek-bansal-VB
Copy link
Author

Other solution for this problem can be: If there would be a function: RemoveWatch(path) exposed by the library. So before deleting the directory I will remove the watch from that directory, and later on when the same directory will be created again, AddWatch(path) method will work on that correctly. Currently AddWatch(path) method is not working correctly since I didn't remove the watch from the directory as there is no method exposed to remove the watch.

@imsodin
Copy link
Contributor

imsodin commented Feb 9, 2021

Might also be fixed by #201 - could you test if it actually is please? @vivek-bansal-VB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants