From 29cbe10857b77f7a2b8182d28b6aa380b0abc012 Mon Sep 17 00:00:00 2001 From: uwetews Date: Fri, 21 Oct 2016 04:00:07 +0200 Subject: [PATCH] - bugfix for compile locking touched timestamp of old compiled file was not restored on compilation error https://github.com/smarty-php/smarty/issues/308 --- change_log.txt | 3 +++ libs/Smarty.class.php | 2 +- libs/sysplugins/smarty_template_compiled.php | 27 +++++++++++++++----- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/change_log.txt b/change_log.txt index 287514bf..b5255a50 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== 3.1.31-dev ===== (xx.xx.xx) + 21.10.2016 + - bugfix for compile locking touched timestamp of old compiled file was not restored on compilation error https://github.com/smarty-php/smarty/issues/308 + 20.10.2016 - bugfix nocache code was not removed in cache file when subtemplate did contain PHP short tags in text but no other nocache code https://github.com/smarty-php/smarty/issues/300 diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index d6dd4028..97fcb445 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.31-dev/37'; + const SMARTY_VERSION = '3.1.31-dev/38'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_template_compiled.php b/libs/sysplugins/smarty_template_compiled.php index b40e3774..18f9d562 100644 --- a/libs/sysplugins/smarty_template_compiled.php +++ b/libs/sysplugins/smarty_template_compiled.php @@ -53,8 +53,8 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base } // if use_sub_dirs, break file into directories if ($smarty->use_sub_dirs) { - $this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . $smarty->ds . $source->uid[ 2 ] . $source->uid[ 3 ] . $smarty->ds . - $source->uid[ 4 ] . $source->uid[ 5 ] . $smarty->ds; + $this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . $smarty->ds . $source->uid[ 2 ] . + $source->uid[ 3 ] . $smarty->ds . $source->uid[ 4 ] . $source->uid[ 5 ] . $smarty->ds; } $this->filepath .= $source->uid . '_'; if ($source->isConfig) { @@ -62,7 +62,8 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base (int) $smarty->config_overwrite * 4; } else { $this->filepath .= (int) $smarty->merge_compiled_includes + (int) $smarty->escape_html * 2 + - (($smarty->merge_compiled_includes && $source->type === 'extends') ? (int) $smarty->extends_recursion * 4 : 0); + (($smarty->merge_compiled_includes && $source->type === 'extends') ? + (int) $smarty->extends_recursion * 4 : 0); } $this->filepath .= '.' . $source->type; $basename = $source->handler->getBasename($source); @@ -192,12 +193,24 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base $this->nocache_hash = null; $this->unifunc = null; // compile locking - if ($saved_timestamp = $this->getTimeStamp()) { + $saved_timestamp = $_template->source->handler->recompiled ? false : $this->getTimeStamp(); + if ($saved_timestamp) { touch($this->filepath); } - // call compiler - $_template->loadCompiler(); - $this->write($_template, $_template->compiler->compileTemplate($_template)); + // compile locking + try { + // call compiler + $_template->loadCompiler(); + $this->write($_template, $_template->compiler->compileTemplate($_template)); + } + catch (Exception $e) { + // restore old timestamp in case of error + if ($saved_timestamp) { + touch($this->filepath, $saved_timestamp); + } + unset($_template->compiler); + throw $e; + } // release compiler object to free memory unset($_template->compiler); }