mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 19:04:27 +02:00
Adding file locking.
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
||||
- added file locking to prevent reader/writer problem. (Andrei)
|
||||
- made Smarty catch unimplemented modifiers and custom functions and output
|
||||
error messages during compilation instead of failing during run time.
|
||||
(Andrei)
|
||||
|
@@ -241,6 +241,9 @@ class Smarty
|
||||
|
||||
function is_cached($tpl_file, $cache_id = null)
|
||||
{
|
||||
if (!$this->caching)
|
||||
return false;
|
||||
|
||||
// cache name = template path + cache_id
|
||||
$cache_tpl_md5 = md5(realpath($this->template_dir.'/'.$tpl_file));
|
||||
$cache_id_md5 = md5($cache_id);
|
||||
@@ -485,7 +488,7 @@ class Smarty
|
||||
if (!($template_contents = $this->_read_file($filepath)))
|
||||
return false;
|
||||
|
||||
$this->_current_file = str_replace($this->template_dir . "/", "", $filepath);
|
||||
$this->_current_file = str_replace($this->template_dir . '/', '', $filepath);
|
||||
$this->_current_line_no = 1;
|
||||
$ldq = preg_quote($this->left_delimiter, '!');
|
||||
$rdq = preg_quote($this->right_delimiter, '!');
|
||||
@@ -1228,11 +1231,13 @@ class Smarty
|
||||
\*======================================================================*/
|
||||
|
||||
function _read_file($filename)
|
||||
|
||||
{
|
||||
if (!($fd = fopen($filename, 'r'))) {
|
||||
$this->_set_error_msg("problem reading '$filename.'");
|
||||
return false;
|
||||
}
|
||||
flock($fd, LOCK_SH);
|
||||
$contents = fread($fd, filesize($filename));
|
||||
fclose($fd);
|
||||
return $contents;
|
||||
@@ -1248,12 +1253,18 @@ class Smarty
|
||||
if($create_dirs)
|
||||
$this->_create_dir_structure(dirname($filename));
|
||||
|
||||
if (!($fd = fopen($filename, 'w'))) {
|
||||
if (!($fd = fopen($filename, 'a'))) {
|
||||
$this->_set_error_msg("problem writing '$filename.'");
|
||||
return false;
|
||||
}
|
||||
fwrite($fd, $contents);
|
||||
flock($fd, LOCK_EX);
|
||||
|
||||
$fd_safe = fopen($filename, 'w');
|
||||
|
||||
fwrite($fd_safe, $contents);
|
||||
fclose($fd_safe);
|
||||
fclose($fd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -241,6 +241,9 @@ class Smarty
|
||||
|
||||
function is_cached($tpl_file, $cache_id = null)
|
||||
{
|
||||
if (!$this->caching)
|
||||
return false;
|
||||
|
||||
// cache name = template path + cache_id
|
||||
$cache_tpl_md5 = md5(realpath($this->template_dir.'/'.$tpl_file));
|
||||
$cache_id_md5 = md5($cache_id);
|
||||
@@ -485,7 +488,7 @@ class Smarty
|
||||
if (!($template_contents = $this->_read_file($filepath)))
|
||||
return false;
|
||||
|
||||
$this->_current_file = str_replace($this->template_dir . "/", "", $filepath);
|
||||
$this->_current_file = str_replace($this->template_dir . '/', '', $filepath);
|
||||
$this->_current_line_no = 1;
|
||||
$ldq = preg_quote($this->left_delimiter, '!');
|
||||
$rdq = preg_quote($this->right_delimiter, '!');
|
||||
@@ -1228,11 +1231,13 @@ class Smarty
|
||||
\*======================================================================*/
|
||||
|
||||
function _read_file($filename)
|
||||
|
||||
{
|
||||
if (!($fd = fopen($filename, 'r'))) {
|
||||
$this->_set_error_msg("problem reading '$filename.'");
|
||||
return false;
|
||||
}
|
||||
flock($fd, LOCK_SH);
|
||||
$contents = fread($fd, filesize($filename));
|
||||
fclose($fd);
|
||||
return $contents;
|
||||
@@ -1248,12 +1253,18 @@ class Smarty
|
||||
if($create_dirs)
|
||||
$this->_create_dir_structure(dirname($filename));
|
||||
|
||||
if (!($fd = fopen($filename, 'w'))) {
|
||||
if (!($fd = fopen($filename, 'a'))) {
|
||||
$this->_set_error_msg("problem writing '$filename.'");
|
||||
return false;
|
||||
}
|
||||
fwrite($fd, $contents);
|
||||
flock($fd, LOCK_EX);
|
||||
|
||||
$fd_safe = fopen($filename, 'w');
|
||||
|
||||
fwrite($fd_safe, $contents);
|
||||
fclose($fd_safe);
|
||||
fclose($fd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user