Andy Wardley <[EMAIL PROTECTED]> writes: > * Fixed a potential race condition when using compiled templates > by changing Template::Document::write_perl_file() to write > to a temporary file and then rename it into place, thus preventing > two separate processes attempting to write the same file at the > same time.
This method (writing to a temporary file and renaming it if all went well) has additional advantages. So here is a request that TT do the same with template output files. Here are the advantages: - the old version remains intact until the new version is completely and successfully written to disc, - if the process dies or bails out early, the old version is still available, - if the old version has multiple names (links or symlinks), only the explicitly named version is changed. That last one bit me recently. I had created a 'preview' subdirectory in an existing site, in which to experiment with a new layout. I linked the files (such as images) that I was not expecting to change from their existing locations into the preview subdirectory and then generated the new html files with TT. Unfortunately I screwed up and had linked not only images but also some of the existing html files. The principle of least astonishment took a hit when I noticed new content in those old files. There is a lot involved in the 'write temporary file / rename' procedure. Well, a lot more than 'open ">$file";print;close' anyway. Securely create the temporary file in the same directory as the desired output file; delete it if the process terminates prematurely; rename after close and possibly copy permissions and ownership; provide workarounds for systems with non-unix semantics. There should be a CPAN module for this. Maybe there IS a module on CPAN, but I didn't find it. -- Frank Cringle, [EMAIL PROTECTED] voice: (+49 7745) 928759; fax: 928761
