Search code examples
javalinuxubuntujnotify

When does JNotify notify creation of a file


Suppose JNotify is listening to a folder named A and I copied a file f to A from folder B which is not part of a sub directory of A. At what exact point of time will JNotify notify.

1) Is it at the point when writing into the new file starts i.e when open() is called on the file to write into it?

OR

2) Is it at the point after the new file is written completely and closed i.e when close() is called on the file after completion of writing into it?

And I am not sure if copying a file involves writing into the file. But I guess it should do so.

I would like to know the scenario in ubuntu(Linux).Any reference is highly appreciated.


Solution

  • JNotify does not make any guaranties as to exact timing of notification delivery. generally it depends on the operating system API, and those APIs can do their own buffering as well (Windows will behave differently than Linux or Mac).

    in most non trivial file creation and writes you will be getting a series of events, not just one. you may want to have a timer on your side to get the point where the events for the file stops to determine that it's safe to operate on.