mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
use tempnam() instead of unqid() to create better temporary files in
smarty_core_write_file(). (thanks to xces for finding this race-condition and his work on fixing it)
This commit is contained in:
2
NEWS
2
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
|
- add 'mail' to escape modifier for safe display of e-mail
|
||||||
addresses (Monte)
|
addresses (Monte)
|
||||||
- add cycle function attribute "reset" to english docs (Monte)
|
- add cycle function attribute "reset" to english docs (Monte)
|
||||||
|
@@ -25,7 +25,7 @@ function smarty_core_write_file($params, &$smarty)
|
|||||||
|
|
||||||
// write to tmp file, then rename it to avoid
|
// write to tmp file, then rename it to avoid
|
||||||
// file locking race condition
|
// file locking race condition
|
||||||
$_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('');
|
$_tmp_file = tempnam($_dirname, 'write_');
|
||||||
|
|
||||||
if (!($fd = @fopen($_tmp_file, 'w'))) {
|
if (!($fd = @fopen($_tmp_file, 'w'))) {
|
||||||
$smarty->trigger_error("problem writing temporary file '$_tmp_file'");
|
$smarty->trigger_error("problem writing temporary file '$_tmp_file'");
|
||||||
@@ -33,10 +33,15 @@ function smarty_core_write_file($params, &$smarty)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fwrite($fd, $params['contents']);
|
fwrite($fd, $params['contents']);
|
||||||
|
|
||||||
|
// Set the file's mtime
|
||||||
if (isset($params['timestamp'])) {
|
if (isset($params['timestamp'])) {
|
||||||
touch($_tmp_file, $params['timestamp']);
|
touch($_tmp_file, $params['timestamp']);
|
||||||
}
|
}
|
||||||
fclose($fd);
|
fclose($fd);
|
||||||
|
|
||||||
|
// Delete the file if it allready exists (this is needed on Win,
|
||||||
|
// because it cannot overwrite files with rename()
|
||||||
if (file_exists($params['filename'])) {
|
if (file_exists($params['filename'])) {
|
||||||
@unlink($params['filename']);
|
@unlink($params['filename']);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user