One event is received when moving of file/folder operation is performed while watching recursively
Shashi-S opened this issue · comments
Hi,
I'm using notify.watch to watch folder recursively on Windows. I was testing few cases with related to both folder and files and I noticed an issue while moving file/folder from one location to another under the directory which being watched. When a file/folder is moved from one directory to another then I see only event being reported i.e., either create or removed.
Here is my observation:
The directory set for watching looks like this C:\Test... and it contains two more nested folder C:\Test\A\B
When a file is moved from A to B then I get "created" event with the path where file is moved to. I don't see the "remove" event from folder A with path.
When a file is moved from B to A I get "removed' event but no created event.
Can you please explain why is this issue seen? Why both source and destination paths cannot be obtained in this case? I verified that the underlying windows API do report both "created" and "removed" events with its appropriate path, but same is not received through the notify.watch wrapper
Similarly, both old name and new file name cannot be seen in the events when file is renamed.
Thanks....
Hey @Shashi-S, could you share your code, how do you setup a watch?
I call the below method (from example code) in the main function
func watchRecursive() {
c := make(chan notify.EventInfo, 1)
if err := notify.Watch("C:\Test\...", c, notify.All);
err != nil {
log.Fatal(err)
}
defer notify.Stop(c)
ei := <-c
log.Println("Got event:", ei)
}
Should I use OS specific events instead of notfiy.All?
Hey @Shashi-S!
Could you increase the buffer size of c
channel? eg. c := make(chan notify.EventInfo, 2)
and retake your tests?
EDIT: Also you should catch events in a loop.
Perhaps the example(s) should be altered to channels with larger buffer sizes than 1
. Seems this confuses a lot of people (cc/ @rjeczalik )
Hi ppknap,
Yes, increasing buffer size of channel works fine.
Thanks for your help.
Thanks to rjeczalik as well.