Skip to content

Commit

Permalink
- bugfix remove deleted files by clear_cache() and clear_compiled_tem…
Browse files Browse the repository at this point in the history
…plate() from

    ACP cache if present, add some is_file() checks to avoid possible warnings on filemtime()
    caused by above functions.
    #341
  • Loading branch information
uwetews committed May 21, 2017
1 parent 61b59a9 commit 4fd1f76
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
4 changes: 4 additions & 0 deletions change_log.txt
Expand Up @@ -2,6 +2,10 @@
21.5.2017
- bugfix remove special treatment of classes implementing ArrayAccess in {foreach}
https://github.com/smarty-php/smarty/issues/332
- bugfix remove deleted files by clear_cache() and clear_compiled_template() from
ACP cache if present, add some is_file() checks to avoid possible warnings on filemtime()
caused by above functions.
https://github.com/smarty-php/smarty/issues/341

19.5.2017
- change properties $accessMap and $obsoleteProperties from private to protected
Expand Down
2 changes: 1 addition & 1 deletion libs/Smarty.class.php
Expand Up @@ -108,7 +108,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.32-dev-5';
const SMARTY_VERSION = '3.1.32-dev-6';

/**
* define variable scopes
Expand Down
Expand Up @@ -101,20 +101,22 @@ public function clearCompiledTemplate(Smarty $smarty, $resource_name = null, $co
$_resource_part_2_length) == 0))
) {
if (isset($exp_time)) {
if (time() - @filemtime($_filepath) >= $exp_time) {
if (is_file($_filepath) && time() - @filemtime($_filepath) >= $exp_time) {
$unlink = true;
}
} else {
$unlink = true;
}
}

if ($unlink && @unlink($_filepath)) {
if ($unlink && is_file($_filepath) && @unlink($_filepath)) {
$_count ++;
if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) {
opcache_invalidate($_filepath, true);
} elseif (function_exists('apc_delete_file')) {
apc_delete_file($_filepath);
}
}
}
Expand Down
36 changes: 20 additions & 16 deletions libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php
Expand Up @@ -111,24 +111,28 @@ public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $e
}
}
}
// expired ?
if (isset($exp_time)) {
if ($exp_time < 0) {
preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_file), $match);
if ($_time < (@filemtime($_file) + $match[ 1 ])) {
continue;
}
} else {
if ($_time - @filemtime($_file) < $exp_time) {
continue;
if (is_file($_filepath)) {
// expired ?
if (isset($exp_time)) {
if ($exp_time < 0) {
preg_match('#\'cache_lifetime\' =>\s*(\d*)#', file_get_contents($_filepath), $match);
if ($_time < (@filemtime($_filepath) + $match[ 1 ])) {
continue;
}
} else {
if ($_time - @filemtime($_filepath) < $exp_time) {
continue;
}
}
}
}
$_count += @unlink($_filepath) ? 1 : 0;
if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) {
opcache_invalidate($_filepath, true);
$_count += @unlink($_filepath) ? 1 : 0;
if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) {
opcache_invalidate($_filepath, true);
} elseif (function_exists('apc_delete_file')) {
apc_delete_file($_filepath);
}
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions libs/sysplugins/smarty_template_compiled.php
Expand Up @@ -173,8 +173,8 @@ public function compileTemplateSource(Smarty_Internal_Template $_template)
$this->nocache_hash = null;
$this->unifunc = null;
// compile locking
$saved_timestamp = $_template->source->handler->recompiled ? false : $this->getTimeStamp();
if ($saved_timestamp) {
if ($saved_timestamp = (!$_template->source->handler->recompiled && is_file($this->filepath))) {
$saved_timestamp = $this->getTimeStamp();
touch($this->filepath);
}
// compile locking
Expand All @@ -185,7 +185,7 @@ public function compileTemplateSource(Smarty_Internal_Template $_template)
}
catch (Exception $e) {
// restore old timestamp in case of error
if ($saved_timestamp) {
if ($saved_timestamp && is_file($this->filepath)) {
touch($this->filepath, $saved_timestamp);
}
unset($_template->compiler);
Expand Down Expand Up @@ -229,6 +229,7 @@ private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl)
if (function_exists('opcache_invalidate')
&& (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)
) {
opcache_invalidate($this->filepath, true);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($this->filepath);
}
Expand Down

0 comments on commit 4fd1f76

Please sign in to comment.