Skip to content

Commit

Permalink
- bugfix for compile locking touched timestamp of old compiled file w…
Browse files Browse the repository at this point in the history
…as not restored on compilation error #308
  • Loading branch information
uwetews committed Oct 21, 2016
1 parent 6699299 commit 29cbe10
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
3 changes: 3 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 20 additions & 7 deletions libs/sysplugins/smarty_template_compiled.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,17 @@ public function populateCompiledFilepath(Smarty_Internal_Template $_template)
}
// 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) {
$this->filepath .= (int) $smarty->config_read_hidden + (int) $smarty->config_booleanize * 2 +
(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);
Expand Down Expand Up @@ -192,12 +193,24 @@ public function compileTemplateSource(Smarty_Internal_Template $_template)
$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);
}
Expand Down

0 comments on commit 29cbe10

Please sign in to comment.