I'm using WatchService
for synchronization data files with the application workbench. When I rename/move the watched directory I don't get any event nor the WatchKey won't become invalid. I still get events from the renamed directory but as far as I know there no way to find out the actual Path for the WatchKey besides WatchKey.watchable()
which however still returns original directory path. I would like to avoid need of locking the watched directory against changes since I want to keep the application as lightweight as possible.
I have experienced this problem with JDK 7u10 on Windows 7
Do you know any workaround for this issue without locking the directory or watching all directories to the root?
UPDATE
On Linux I have observed the same behavior.
So far it seems I have three options now.
1) Rely on user's discipline that he/she won't move the data directories. I don't really like this options since it might lead to undefined behavior.
2) Use more extensive non-standard native library
3) Create hierarchy of watchdogs on superior directories. These would accept only ENTRY_DELETE
events since this event (or OVERFLOW
) must appear at the moment the actual watched directory is moved or deleted and thus invalid.