php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45986 rename() generates Bad file descriptor
Submitted: 2008-09-03 17:02 UTC Modified: 2010-01-26 22:17 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: david at grudl dot com Assigned: pajoye (profile)
Status: Closed Package: Filesystem function related
PHP Version: 5.3CVS-2008-11-11 OS: win32 only
Private report: No CVE-ID: None
 [2008-09-03 17:02 UTC] 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...


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-12 18:53 UTC] 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.
 [2010-01-26 20:04 UTC] 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-26 22:17 UTC] pajoye@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 07:01:32 2024 UTC