diff --git a/NEWS b/NEWS index 572b350d..d5b787a3 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ + - use tempnam() instead of unqid() to create better temporary files in + smarty_core_write_file() (xces, messju) - add 'mail' to escape modifier for safe display of e-mail addresses (Monte) - add cycle function attribute "reset" to english docs (Monte) diff --git a/libs/core/core.write_file.php b/libs/core/core.write_file.php index b4fa92e5..d6de7311 100644 --- a/libs/core/core.write_file.php +++ b/libs/core/core.write_file.php @@ -25,7 +25,7 @@ function smarty_core_write_file($params, &$smarty) // write to tmp file, then rename it to avoid // file locking race condition - $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid(''); + $_tmp_file = tempnam($_dirname, 'write_'); if (!($fd = @fopen($_tmp_file, 'w'))) { $smarty->trigger_error("problem writing temporary file '$_tmp_file'"); @@ -33,11 +33,16 @@ function smarty_core_write_file($params, &$smarty) } fwrite($fd, $params['contents']); + + // Set the file's mtime if (isset($params['timestamp'])) { touch($_tmp_file, $params['timestamp']); } fclose($fd); - if(file_exists($params['filename'])) { + + // Delete the file if it allready exists (this is needed on Win, + // because it cannot overwrite files with rename() + if (file_exists($params['filename'])) { @unlink($params['filename']); } @rename($_tmp_file, $params['filename']);