Posted on 2009-11-06 14:54:50-08 by rkstar
XML File locking?
I'm currently writing a program that will read and write to an XML file a lot. What sort of protection is there from XMLin trying to read a file that's currently being written to? I can't find any mention anywhere.
Direct Responses: 11721 | Write a response
Posted on 2009-11-06 15:24:16-08 by exiftool in response to 11719
Re: XML File locking?
If you're on Windows, the operating system won't let you do this. On other operating systems you'll have to do something like create a temporary ".lock" file and not process the XML file if a ".lock" file exists. You must be careful because there is a race condition creating the .lock file so you must be able to tell which process created it first. I usually write the process number to the file then read back the first line of the file to make sure it is my process. Otherwise some other process created the .lock file so the current process must wait until it is deleted by the owning process.
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.