From 4286ad068bf4bed5b879ac6ace47612ea45fcc0a Mon Sep 17 00:00:00 2001 From: "Uwe.Tews" Date: Wed, 18 Nov 2009 17:25:18 +0000 Subject: [PATCH] - observe umask settings when setting file permissions - avoide unneeded cache file creation for subtemplates which did occur in some situations --- change_log.txt | 4 ++++ libs/Smarty.class.php | 2 +- libs/sysplugins/smarty_internal_compile_include.php | 4 +++- libs/sysplugins/smarty_internal_debug.php | 6 +++--- libs/sysplugins/smarty_internal_template.php | 4 ++-- libs/sysplugins/smarty_internal_write_file.php | 4 +++- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/change_log.txt b/change_log.txt index 2e6a4982..5455deb3 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,3 +1,7 @@ +11/18/2009 +- observe umask settings when setting file permissions +- avoide unneeded cache file creation for subtemplates which did occur in some situations + 11/17/2009 - sanitize compile_id and cache_id (replace illegal chars with _) - use _dir_perms and _file_perms properties at file creation diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index e37ea0d0..ecabcae0 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -136,7 +136,7 @@ class Smarty extends Smarty_Internal_TemplateBase { // caching enabled public $caching = false; // merge compiled includea - public $merge_compiled_includes = true; + public $merge_compiled_includes = false; // cache lifetime public $cache_lifetime = 0; // force cache file creation diff --git a/libs/sysplugins/smarty_internal_compile_include.php b/libs/sysplugins/smarty_internal_compile_include.php index 07b1e6c4..56198e42 100644 --- a/libs/sysplugins/smarty_internal_compile_include.php +++ b/libs/sysplugins/smarty_internal_compile_include.php @@ -101,7 +101,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { } // default for included templates if ($this->compiler->template->caching && !$this->compiler->nocache) { - $_caching = SMARTY_CACHING_LIFETIME_CURRENT; + $_caching = 9999; } else { $_caching = SMARTY_CACHING_OFF; } @@ -113,6 +113,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { if (isset($_attr['cache_lifetime'])) { $_cache_lifetime = $_attr['cache_lifetime']; $this->compiler->tag_nocache = true; + $_caching = SMARTY_CACHING_LIFETIME_CURRENT; } if (isset($_attr['nocache'])) { if ($_attr['nocache'] == 'true') { @@ -124,6 +125,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase { if ($_attr['caching'] == 'true') { $_caching = SMARTY_CACHING_LIFETIME_CURRENT; } else { + $this->compiler->tag_nocache = true; $_caching = SMARTY_CACHING_OFF; } } diff --git a/libs/sysplugins/smarty_internal_debug.php b/libs/sysplugins/smarty_internal_debug.php index b85a1d7c..9e5f7bed 100644 --- a/libs/sysplugins/smarty_internal_debug.php +++ b/libs/sysplugins/smarty_internal_debug.php @@ -31,7 +31,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_TemplateBase { public static function end_compile($template) { $key = self::get_key($template); - self::$template_data[$key]['compile_time'] = self::get_time() - self::$template_data[$key]['start_time']; + self::$template_data[$key]['compile_time'] += self::get_time() - self::$template_data[$key]['start_time']; } /** @@ -49,7 +49,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_TemplateBase { public static function end_render($template) { $key = self::get_key($template); - self::$template_data[$key]['render_time'] = self::get_time() - self::$template_data[$key]['start_time']; + self::$template_data[$key]['render_time'] += self::get_time() - self::$template_data[$key]['start_time']; } /** @@ -67,7 +67,7 @@ class Smarty_Internal_Debug extends Smarty_Internal_TemplateBase { public static function end_cache($template) { $key = self::get_key($template); - self::$template_data[$key]['cache_time'] = self::get_time() - self::$template_data[$key]['start_time']; + self::$template_data[$key]['cache_time'] += self::get_time() - self::$template_data[$key]['start_time']; } /** * Opens a window for the Smarty Debugging Consol and display the data diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 12d7bc5a..84f9b4d8 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -372,7 +372,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase { if ($this->getCachedTimestamp() === false) { return $this->isCached; } - if ($this->caching === SMARTY_CACHING_LIFETIME_SAVED || ($this->caching && (time() <= ($this->getCachedTimestamp() + $this->cache_lifetime) || $this->cache_lifetime < 0))) { + if ($this->caching === SMARTY_CACHING_LIFETIME_SAVED || ($this->caching == SMARTY_CACHING_LIFETIME_CURRENT && (time() <= ($this->getCachedTimestamp() + $this->cache_lifetime) || $this->cache_lifetime < 0))) { if ($this->smarty->debugging) { Smarty_Internal_Debug::start_cache($this); } @@ -481,7 +481,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase { Smarty_Internal_Debug::end_render($this); } // write to cache when nessecary - if (!$this->isEvaluated() && $this->caching) { + if (!$this->isEvaluated() && ($this->caching == SMARTY_CACHING_LIFETIME_SAVED || $this->caching == SMARTY_CACHING_LIFETIME_CURRENT)) { if ($this->smarty->debugging) { Smarty_Internal_Debug::start_cache($this); } diff --git a/libs/sysplugins/smarty_internal_write_file.php b/libs/sysplugins/smarty_internal_write_file.php index 85481150..437053bf 100644 --- a/libs/sysplugins/smarty_internal_write_file.php +++ b/libs/sysplugins/smarty_internal_write_file.php @@ -20,6 +20,7 @@ class Smarty_Internal_Write_File { */ public static function writeFile($_filepath, $_contents, $smarty) { + $old_umask = umask(0); $_dirpath = dirname($_filepath); // if subdirs, create dir structure if ($_dirpath !== '.' && !file_exists($_dirpath)) { @@ -29,6 +30,7 @@ class Smarty_Internal_Write_File { $_tmp_file = tempnam($_dirpath, 'wrt'); if (!file_put_contents($_tmp_file, $_contents)) { + umask($old_umask); throw new Exception("unable to write file {$_tmp_file}"); return false; } @@ -39,7 +41,7 @@ class Smarty_Internal_Write_File { rename($_tmp_file, $_filepath); // set file permissions chmod($_filepath, $smarty->_file_perms); - + umask($old_umask); return true; } }