WatchService / detecting renames and moves

Alan Bateman Alan.Bateman at oracle.com
Wed Jan 11 04:12:21 PST 2012


On 10/01/2012 14:40, Johannes.Lichtenberger wrote:
> :
> So, is it save to assume that renames or moves, that is maybe a
> file/directory has been moved from one watched directory to another
> watched directory (I'm watching recursively all sub-directories) come in
> pairs of CREATE/DELETE events or DELETE/CREATE events without any other
> events between these pairs? For instance can I assume that all I have to
> do is to keep one event temporarily and compare the fileKey of the last
> and the current event to detect if it's a rename or if the parent path
> changes to detect a move?
This wouldn't be a safe assumption as other events could be interleaved. 
You might not be able to see this on Linux or Windows but it should be 
easy to demonstrate this on Solaris (10 at least) or Mac. All I can 
suggest is to cache the fileKey for a short time when you get these events.

> :
>
> That said I just want to keep a database (tree-structured) up to date
> which allows renames and subtree-moves, which I'm going to visualize
> afterwards (for instance the attached screenshot which currently only
> visualizes INSERTS/DELETES between snapshots). As it can also visualize
> moves and renames/updates of nodes I want to support it within my
> directory-watching application in the first place.
>
It's interesting to see this visualized.

-Alan


More information about the nio-discuss mailing list