ID:               45986
 Comment by:       michael-l-smith at att dot net
 Reported By:      david at grudl dot com
 Status:           Assigned
 Bug Type:         Filesystem function related
 Operating System: win32 only
 PHP Version:      5.3CVS-2008-11-11
 Assigned To:      pajoye
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[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

Reply via email to