WatchService / detecting renames and moves

Johannes.Lichtenberger Johannes.Lichtenberger at uni-konstanz.de
Mon Jan 9 11:56:12 PST 2012


Hello,

I'm using a WatchService to monitor changes in a directory recursively.
Now I want to add a simple rename or move-detection. Therefore I
probably can use java.nio.file.attribute.BasicFileAttributes.fileKey()
but I think the order in which I receive events isn't specified (CREATE
=> DELETE, DELETE => CREATE) or is it also possible to get other CREATE
/ DELETE events between the events originating from a move or
rename-operation? That would for sure complicate the situation, but I
think that's possible because I haven't read anything which guarantees
any order. Furthermore the fileKeys can be reused by the Filesystem,
which is also why I'm questioning my approach. Maybe using hashes and
the fileKeys... but I don't want to save a new queue of events, which
would be a heuristic, because after some time no equal fileKey + hash is
encountered I would suggest they are "real" DELETE/CREATE-events. Maybe
I should simply switch to JPathWatch as it should definately work on
Linux and optionally on Windows, which both seem to support and "export"
move-events)?

kind regards,
Johannes


More information about the nio-discuss mailing list