Java7 watchservice – how to detect renaming / moving of the actual monitoring directory

I am using watchservice to synchronize data files with the application workbench When I rename / move a monitored directory, I do not receive any events and will not invalidate the watchkey I still get events from the renamed directory, but as far as I know, except watchkey In addition to watchable(), the actual path of watchkey has not been found, but the original directory path is still returned I want to avoid locking the watch directory on changes because I want to keep the application as easy as possible

I encountered this problem with JDK 7u10 on Windows 7

Do you know any solution to this problem without locking the directory or seeing all directories as the root directory?

UPDATE

I observed the same behavior on Linux

So far, I have three choices

1) Depending on the user's discipline, he / she will not move the data directory I don't like this option very much because it may lead to undefined behavior

2) Wider use of non specimen repositories

3) Create a watchdog hierarchy on the parent directory These will only accept entry_ Delete event, which appears when it is invalid because this event (or overflow) must be moved or deleted in the actually monitored directory

Solution

My understanding is that renaming a directory will generate file system events on the old and new parent directories, not the renamed directory According to can inotify tell me where a monitored file is moved? The operating system cannot tell you where to move unless you are monitoring the target directory (in addition, in Java 7 / 8, the move event is not handled by the watch service.)

UPDATE

You can try using the standard Java 7 watchservice API to add a jpathwatch project that supports platform specific extended events

reference:

>Documentation – http://jpathwatch.wordpress.com/ > javadoc – http://jpathwatch.sourceforge.net/

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>