tags:

views:

87

answers:

1

I'm working on a project that generates Google Earth KML files and saves the file to a web-accessible directory. It's running on Windows with ActivePerl. (not my preferred platform but it's what I must work with.)

The method I'm using for this is: write to temp.kml, use File::Copy to copy temp.kml to real.kml. This occurs once a second.

Google Earth grabs this real.kml via an apache2 webserver. The problem is, errors get thrown when Google Earth grabs the real.kml at the same time as temp.kml is being copied to real.kml.

I understand that there's a good chance this is unavoidable, but is there any way that I can minimize the frequency of errors thrown?

+2  A: 

Instead of copying the file, why not just move it from your temp directory to the web directory once your processing has finished? If your temp directory is on the same filesystem as the web directory, this should result in only the name of the file changing, while the contents remain unchanged. There should be a smaller chance of a race condition.

Use file::Copy to move file

Gary
thanks, I'm testing out File::Copy's move() now.
roamn
I think it would eliminate a race condition on Linux.
Brad Gilbert
so far I have been stress testing it and have not been able to raise a race condition on windows. it appears as though this was the fix I was looking for, thanks!
roamn