#45986 [Asn->Csd]: rename() generates Bad file descriptor
| From: | pajoye@php.net | Date: | Tue, 26 Jan 2010 22:17:12 +0000 |
| Subject: | #45986 [Asn->Csd]: rename() generates Bad file descriptor | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-146966@lists.php.net to get a copy of this message | ||
ID: 45986
Updated by: pajoye@php.net
Reported By: david at grudl dot com
-Status: Assigned
+Status: Closed
Bug Type: Filesystem function related
Operating System: win32 only
PHP Version: 5.3CVS-2008-11-11
Assigned To: pajoye
New Comment:
This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2010-01-26 20:04:04] svn@php.net
Automatic comment from SVN on behalf of pajoye
Revision: http://svn.php.net/viewvc/?view=revision&revision=294053
Log: - [DOC] #45986, bad file descriptor warning when rename is used
with invalid path, add php_win32_docref2_from_error to display system
error for non posix api
------------------------------------------------------------------------
[2010-01-12 18:53:52] michael-l-smith at att dot net
I also observe this issue in multiple Windows OS'. Below is the
offending code:
echo "Modifying $file\n";
$currentFile = str_replace("c:","C:",$testFileDirectory) . "\\" .
$file;
$fh = fopen($currentFile, 'r') or die("can't open the original
file");
$tmpfile = getcwd() . "\\temp\\" . rand();
$fp = fopen($tmpfile, 'a') or die("can't open tmp file");
$temporaryString = "";
while ($tmpStringData = fread($fh,1024))
{
$stringLength = mb_strlen($tmpStringData);
$coinFlip = rand(0,1);
switch ($coinFlip)
{
case 0:
while (mb_strlen($temporaryString) < $stringLength)
{
$temporaryString = $temporaryString . rand(0,9);
}
fwrite($fp,$temporaryString);
break;
case 1:
fwrite($fp,$tmpStringData);
break;
}//end switch
}//end while
fclose($fh);
fclose($fp);
rename($tmpfile,$currentFile) or die("Unable to rename the tmp
file.");
$fileToMD5 = getCWD() . str_replace("c:","C:",$testFileDirectory) .
"\\";
addMD5($currentFile);
The error occurs during the rename() after fclose(). It seems that the
file is locked or otherwise prevented from being renamed. Perhaps
fclose() is lagging somehow? I have verified that the file does, in
fact, exist when this issue occurs.
------------------------------------------------------------------------
[2008-09-03 17:02:39] david at grudl dot com
Description:
------------
Renaming of non-existent file generates in PHP 5.2.6 warning:
Warning: rename(foo,bar) [function.rename]: No such file or
directory
And in PHP 5.3.0 alpha2 it generates warning:
Warning: rename(foo,bar): Bad file descriptor
I am not sure, but maybe this points to any hidden bug in renaming
routine...
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=45986&edit=1