0

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.

2rd_7
  • 462
  • 1
  • 3
  • 15

1 Answers1

1

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.

Omry Yadan
  • 31,280
  • 18
  • 64
  • 87
  • Thanks, Can you post any reference. I couldn't find one after many hours of searching. Or should I test it by myself by creating some large file? – 2rd_7 Jun 09 '16 at 05:03
  • reference to what? I know this because I wrote JNotify. – Omry Yadan Jun 10 '16 at 01:28
  • Oh!!! I'm sorry. I did not have an idea. And I verified your statement few minutes ago. I wrote a C++ program which writes into a txt file indefinitely but I get the notification just after 'open()' is called. Thanks anyways :) !!! – 2rd_7 Jun 10 '16 at 06:13
  • yeah, you will typically get an event when a file is opened and one or more events when it's flushed (depending on how much data is flushed). – Omry Yadan Jun 10 '16 at 17:16