I implemented a file watcher but I noticed that java nio file watcher doesn't generate events for files being copied on mapped drives. For instance, I've run the file watcher on Unix to watch a local directory (/sharedfolder
) which is mapped on windows (H:\
), and then I've put a file in this directory (H:\
) but the file watcher hasn't generated any event. Now if I run the file watcher on windows to watcher the mapped drive (H:\
) which refers to a unix path (/sharedfolder
) and from unix I put a file in this folder, the file watcher identifies the change and generates an event. It looks like a bug, or may be I'm missing some thing, any thoughts?
I have the same issue trying to watch a mounted windows share via CIFS. It seems not possible to get filesystem events for CIFS mounts.
The linux implementation of the Java 7 NIO FileWatcher uses inotify. Inotify is a linux kernel subsystem to notice filesystem changes which works perfect for local directories, but apparently not for CIFS mounts.
At Oracle, it doesn't seem to be high priority to fix this bug. (Is it their responsibility? More of an OS issue...)
JNotify also uses inotify on linux systems, so this is no option either.
So mapped drives monitoring unfortunately seems to be limited to pollers:
I'll probably try the Apache VFS Monitor, because it detects file creation, updates and deletes out of the box. It requires to mount the share, but that gives the OS the responsibility of CIFS connections and not my application.
File watching functionality in JDK is platform dependent as it uses native libraries so it could behave differently on different platform. I'm surprised it works for network drives at all - Windows must be polling network mapped drives for changes while Linux doesn't (rightfully so I should say).
Usually this sort of monitoring implemented in OS kernel, which obviously has knowledge which files are modified/created/etc locally but there are no easy ways for OS to know what happening on network drive as it doesn't have exclusive control over it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With