Java WatchService not generating events while watching mapped drives

后端 未结 5 1839
春和景丽
春和景丽 2020-11-30 05:58

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 watc

5条回答
  •  借酒劲吻你
    2020-11-30 06:30

    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:

    • Apache VFS DefaultFileMonitor to poll directories (mounted share)
    • File Poller based on the standard Java API.
    • Custom File Poller with jCIFS (so the share doesn't need to be mounted on the host)

    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.

提交回复
热议问题