Re: [SMARTY] Re: windows problem with loads of *.tmp files - MORE info
Jan Rosier <[email protected]>
| Newsgroups | gmane.comp.php.smarty.general |
|---|---|
| Message-ID | <[email protected]> |
The attached php file got lost. This time the file is attached as text file. Hope this works... Greetings, Jan Rosier Jan Rosier wrote: > I think the problem is in the file libs/internals/core.write_file.php. > Try the patched version attached to this mail. > > Here is what I think is happening: > At line 28 an temp file is created, then at line 30 this file is > opened for writing. > If opening the temp file fails Smarty will try to create a temp file > using uniqid() (line 31) > But the temp file already created at line 28 isn't removed first. > > I also attached a diff to the last version that is in the cvs. > > Greetings, > Jan Rosier > > -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
patched.core.write_file.php.txt
(text/plain, 1.4 KB)
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* write out a file to disk
*
* @param string $filename
* @param string $contents
* @param boolean $create_dirs
* @return boolean
*/
function smarty_core_write_file($params, &$smarty)
{
$_dirname = dirname($params['filename']);
if ($params['create_dirs']) {
$_params = array('dir' => $_dirname);
require_once(SMARTY_CORE_DIR . 'core.create_dir_structure.php');
smarty_core_create_dir_structure($_params, $smarty);
}
// write to tmp file, then rename it to avoid
// file locking race condition
$_tmp_file = tempnam($_dirname, 'wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
if (file_exists($_tmp_file)) {
@unlink($_tmp_file);
}
$_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
$smarty->trigger_error("problem writing temporary file '$_tmp_file'");
return false;
}
}
fwrite($fd, $params['contents']);
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'])) {
@unlink($params['filename']);
}
@rename($_tmp_file, $params['filename']);
@chmod($params['filename'], $smarty->_file_perms);
return true;
}
/* vim: set expandtab: */
?>