diff --git a/change_log.txt b/change_log.txt index 3fd9dd352..2773e0a0c 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,7 +1,8 @@  ===== 3.1.22-dev ===== (xx.xx.2015) 04.05.2015 - bugfix Smarty_Resource::parseResourceName incompatible with Google AppEngine (https://github.com/smarty-php/smarty/issues/22) - + - improvement use is_file() checks to avoid errors suppressed by @ which could still cause problems (https://github.com/smarty-php/smarty/issues/24) + 28.04.2015 - bugfix plugins of merged subtemplates not loaded in 3.1.22-dev (forum topic 25508) 2nd fix diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 231a62b1f..dff28d21b 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.22-dev/22'; + const SMARTY_VERSION = '3.1.22-dev/23'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index cbb38e3ba..72ed76925 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -61,8 +61,10 @@ public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Templat $cached->lock_id = $_lock_dir . sha1($_cache_id . $_compile_id . $_template->source->uid) . '.lock'; } $cached->filepath = $_cache_dir . $_cache_id . $_compile_id . $_filepath . '.' . basename($_source_file_path) . '.php'; - $cached->timestamp = @filemtime($cached->filepath); - $cached->exists = !!$cached->timestamp; + $cached->exists = is_file($cached->filepath); + if ($cached->exists) { + $cached->timestamp = filemtime($cached->filepath); + } } /** @@ -74,8 +76,10 @@ public function populate(Smarty_Template_Cached $cached, Smarty_Internal_Templat */ public function populateTimestamp(Smarty_Template_Cached $cached) { - $cached->timestamp = @filemtime($cached->filepath); - $cached->exists = !!$cached->timestamp; + $cached->timestamp = $cached->exists = is_file($cached->filepath); + if ($cached->exists) { + $cached->timestamp = filemtime($cached->filepath); + } } /** @@ -108,13 +112,13 @@ public function writeCachedContent(Smarty_Internal_Template $_template, $content { $obj = new Smarty_Internal_Write_File(); if ($obj->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) { - $_template->cached->timestamp = @filemtime($_template->cached->filepath); - $_template->cached->exists = !!$_template->cached->timestamp; - if ($_template->cached->exists) { + $cached = $_template->cached; + $cached->timestamp = $cached->exists = is_file( $cached->filepath); + if ($cached->exists) { + $cached->timestamp = filemtime($cached->filepath); return true; } } - return false; } @@ -278,9 +282,12 @@ public function hasLock(Smarty $smarty, Smarty_Template_Cached $cached) } else { clearstatcache(); } - $t = @filemtime($cached->lock_id); - - return $t && (time() - $t < $smarty->locking_timeout); + if (is_file($cached->lock_id)) { + $t = @filemtime($cached->lock_id); + return $t && (time() - $t < $smarty->locking_timeout); + } else { + return false; + } } /** diff --git a/libs/sysplugins/smarty_internal_extension_defaulttemplatehandler.php b/libs/sysplugins/smarty_internal_extension_defaulttemplatehandler.php index bf25eb915..ed6029204 100644 --- a/libs/sysplugins/smarty_internal_extension_defaulttemplatehandler.php +++ b/libs/sysplugins/smarty_internal_extension_defaulttemplatehandler.php @@ -35,8 +35,10 @@ static function _getDefault(Smarty_Internal_Template $_template, &$source, &$res $_return = call_user_func_array($default_handler, array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty)); if (is_string($_return)) { - $source->timestamp = @filemtime($_return); - $source->exists = !!$source->timestamp; + $source->exists = is_file($_return); + if ($source->exists) { + $source->timestamp = filemtime($_return); + } $source->filepath = $_return; } elseif ($_return === true) { $source->content = $_content; diff --git a/libs/sysplugins/smarty_internal_resource_file.php b/libs/sysplugins/smarty_internal_resource_file.php index a97ed46b5..95d229652 100644 --- a/libs/sysplugins/smarty_internal_resource_file.php +++ b/libs/sysplugins/smarty_internal_resource_file.php @@ -169,8 +169,10 @@ public function populate(Smarty_Template_Source $source, Smarty_Internal_Templat $source->uid = sha1(getcwd() . $source->filepath); if ($source->smarty->compile_check && !isset($source->timestamp)) { - $source->timestamp = @filemtime($source->filepath); - $source->exists = !!$source->timestamp; + $source->timestamp = $source->exists = is_file($source->filepath); + if ($source->exists) { + $source->timestamp = @filemtime($source->filepath); + } } } else { $source->timestamp = false; @@ -185,8 +187,10 @@ public function populate(Smarty_Template_Source $source, Smarty_Internal_Templat */ public function populateTimestamp(Smarty_Template_Source $source) { - $source->timestamp = @filemtime($source->filepath); - $source->exists = !!$source->timestamp; + $source->timestamp = $source->exists = is_file($source->filepath); + if ($source->exists) { + $source->timestamp = @filemtime($source->filepath); + } } /** diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 59fdae759..d47613f96 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -599,8 +599,8 @@ public function decodeProperties($properties, $cache = false) $mtime = $this->source->timestamp; } else { // file and php types can be checked without loading the respective resource handlers - $mtime = @filemtime($_file_to_check[0]); - } + $mtime = is_file($_file_to_check[0]) ? @filemtime($_file_to_check[0]) : false; + } } elseif ($_file_to_check[2] == 'string') { continue; } else { diff --git a/libs/sysplugins/smarty_internal_write_file.php b/libs/sysplugins/smarty_internal_write_file.php index 54dbbe8f8..9ecc7c0c8 100644 --- a/libs/sysplugins/smarty_internal_write_file.php +++ b/libs/sysplugins/smarty_internal_write_file.php @@ -55,7 +55,9 @@ public function writeFile($_filepath, $_contents, Smarty $smarty) */ if (Smarty::$_IS_WINDOWS) { // remove original file - @unlink($_filepath); + if (is_file($_filepath)) { + @unlink($_filepath); + } // rename tmp file $success = @rename($_tmp_file, $_filepath); } else { @@ -63,17 +65,17 @@ public function writeFile($_filepath, $_contents, Smarty $smarty) $success = @rename($_tmp_file, $_filepath); if (!$success) { // remove original file - @unlink($_filepath); + if (is_file($_filepath)) { + @unlink($_filepath); + } // rename tmp file $success = @rename($_tmp_file, $_filepath); } } - if (!$success) { error_reporting($_error_reporting); throw new SmartyException("unable to write file {$_filepath}"); } - if ($smarty->_file_perms !== null) { // set file permissions chmod($_filepath, $smarty->_file_perms); diff --git a/libs/sysplugins/smarty_template_compiled.php b/libs/sysplugins/smarty_template_compiled.php index 22d9418fc..8776a0916 100644 --- a/libs/sysplugins/smarty_template_compiled.php +++ b/libs/sysplugins/smarty_template_compiled.php @@ -130,8 +130,10 @@ public function populateCompiledFilepath(Smarty_Internal_Template $_template) } $this->filepath = $_compile_dir . $_filepath . '.' . $_template->source->type . $_basename . $_cache . '.php'; - $this->timestamp = @filemtime($this->filepath); - $this->exists = !!$this->timestamp; + $this->timestamp = $this->exists = is_file($this->filepath); + if ($this->exists) { + $this->timestamp = @filemtime($this->filepath); + } } /** @@ -252,12 +254,12 @@ public function write(Smarty_Internal_Template $_template, $code) if (!$_template->source->recompiled) { $obj = new Smarty_Internal_Write_File(); if ($obj->writeFile($this->filepath, $code, $_template->smarty) === true) { - $this->timestamp = @filemtime($this->filepath); - $this->exists = !!$this->timestamp; + $this->timestamp = $this->exists = is_file($this->filepath); if ($this->exists) { + $this->timestamp = @filemtime($this->filepath); return true; } - } + } return false; } else { $this->code = $code;