0

I have to write a Plugin, which is called from another component. The plugin should look for files in a given network share and if there are new files, they should be copied elsewhere.

Unfortunately when there are bigger files, it can happen that my plugin is called before the file writing to the source directory is complete, which means that I'm copying just a part of the file.

I found solutions to watch the process who writes the file or use FileWatcher to watch the directory, but since I'm copying from a network share and my plugin is called from the outside, this wouldn't work for me - would it?

I have to guarantee that the files I can find within the network share are complete. Is there something like a check, if all bytes are written or something like that?`

Thanks in advance

areiterer
  • 33
  • 1
  • 7
  • No, there isn't because the only program that has a chance to know how long the file is supposed to be is the program writing to the file, and this program has no place to put this number **in the general case**. If, on the other hand, you control the software that also writes these files then you can do stuff, like add a marker file alongside the original file only when writing is complete, prefix the file contents with its size, etc. But no, in the general case, if you're allowed to open the file you have no way to figure out if the file has "been completely written". – Lasse V. Karlsen Aug 26 '16 at 06:56
  • Have you considered altering the software putting the files there, or running software using the FileWatcher on the same server as the files? – Lasse V. Karlsen Aug 26 '16 at 06:57
  • This is a very common issue. You can never be sure that something isnt just holding out on you and going to add just that teeny bit more.. Best way I know of is to hope that by taking an exclusive lock of the file, you block updates.. but that could mean that the originating app now cant finish its update. Quite a few people rely on the "if it hasnt changed for a while, it must be done" process. – BugFinder Aug 26 '16 at 06:57

0 Answers0