WatchService / detecting renames and moves
Alan Bateman
Alan.Bateman at oracle.com
Tue Jan 10 03:33:15 PST 2012
On 09/01/2012 19:56, Johannes.Lichtenberger wrote:
> 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
Rename or move-in/out events aren't strictly required as the CREATE and
DELETE events should allow you to keep your view of the directory up to
the date. The reason that these events weren't included originally is
because out of concern that they would not be feasible with all
implementations and also the concern as to how such events would be
linked when renaming between directories. That said, it is something
that we should come back to. As regards the fileKey() method then in
theory it could be recycled quickly although in practice it should do
what you want on the platforms where fileKey() returns non-null.
-Alan
More information about the nio-discuss
mailing list