From 0ef667f4c70d5da55539b0e357d14eae402eae0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 8 Sep 2014 18:06:16 +0200 Subject: [PATCH] Write compiled templates atomically --- .../template/TemplateCompiler.class.php | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) 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(); } /** -- 2.20.1