From: Tim Düsterhus Date: Mon, 8 Sep 2014 16:06:16 +0000 (+0200) Subject: Write compiled templates atomically X-Git-Tag: 2.1.0_Alpha_1~344^2~32^2~1^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0ef667f4c70d5da55539b0e357d14eae402eae0f;p=GitHub%2FWoltLab%2FWCF.git Write compiled templates atomically --- diff --git a/wcfsetup/install/files/lib/system/template/TemplateCompiler.class.php b/wcfsetup/install/files/lib/system/template/TemplateCompiler.class.php index 7c0cdfd208..7bb759c6e2 100644 --- a/wcfsetup/install/files/lib/system/template/TemplateCompiler.class.php +++ b/wcfsetup/install/files/lib/system/template/TemplateCompiler.class.php @@ -1,6 +1,6 @@ v['tpl']['template'] = '".addcslashes($templateName, "'\\")."';\n?>\n"; + $writer->write("v['tpl']['template'] = '".addcslashes($templateName, "'\\")."';\n?>\n"); // include plug-ins $compiledContent = $this->compileString($templateName, $sourceContent, $metaData); - - // write compiled template to file - $file = new File($compiledFilename); - $file->write($compiledHeader.$compiledContent['template']); - $file->close(); + $writer->write($compiledContent['template']); // write meta data to file $this->saveMetaData($templateName, $metaData['filename'], $compiledContent['meta']); + + $writer->flush(); + $writer->close(); } /** @@ -45,10 +45,11 @@ class TemplateCompiler extends TemplateScriptingCompiler { * @param string $content */ public function saveMetaData($templateName, $filename, $content) { - $file = new File($filename); - $file->write("\n"); - $file->write(serialize($content)); - $file->close(); + $writer = new AtomicWriter($filename); + $writer->write("\n"); + $writer->write(serialize($content)); + $writer->flush(); + $writer->close(); } /**