When using JNotify on Linux you will not get notified when a file is moved out-of or in-to a watched directory.
This is issue has been known for a while but I thought it should be more visible so people aren't caught off guard.
Reported against: 0.91
Logged In: YES
user_id=1709775
Originator: YES
And now to comment on possible work arounds: From my limited understanding of JNotify and Linux's inotify API the problem lies in JNotify's abstaction. In inotify there really is no single "renamed" event. Instead a rename is reported by inotify as a pair of events: IN_MOVED_FROM and IN_MOVED_TO. For a renamed file these two events will share the same "cookie" identifier so you know they are related. When a file is merely moved in to or out of the watched directory you will get only one of these events.
Solution "A" would be to ditch JNotify's renamed event because it is "not portable". Instead a rename would be reported as a delete followed by a create. Kind of a shame...
Solution "B" would be to try simulate the rename event. Down in the C code, when reading from inotify's event queue if you see an IN_MOVED_FROM then peek the queue again before reporting it. If the queue holds IN_MOVED_TO with the same cookie id then you have a renamed event, otherwise it's a file moved out of your directory. But that wouldn't quite cover the bases. Because we can't be certain that if it were a rename event the queue would already have IN_MOVED_TO. Perhaps the kernel got interrupted before putting in the second half. Or perhaps another process got a time slice and filled the queue with other notifications. To handle such uncertainties I would suggest that when you see a IN_MOVED_FROM do another short blocking read on the queue (say 100ms). If after that timeout you still don't see IN_MOVED_TO then assume it's not a "rename".
Logged In: YES
user_id=126268
Originator: NO
Thanks, just saw this.
I no longer have time for JNotify, but if you will send a patch I`ll evaluate it for inclusion.
Okay, I've just been caught off guard by this bug and I'd like to add that on my Ubuntu install the move-into notification works, while the move-out-of doesn't.
https://sourceforge.net/tracker/?func=detail&aid=2855285&group_id=154048&atid=790220
will explain and fix this problem