#44870 [Asn->Csd]: rename() on directory deletes same named file

From: Date: Fri, 02 May 2008 14:18:43 +0000
Subject: #44870 [Asn->Csd]: rename() on directory deletes same named file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-124658@lists.php.net to get a copy of this message
ID: 44870 Updated by: derick@php.net Reported By: ant@php.net -Status: Assigned +Status: Closed Bug Type: Streams related Operating System: Windows/XP PHP Version: 5.3CVS-2008-04-30 (snap) Assigned To: pajoye New Comment: This bug has been fixed in CVS. 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: ------------------------------------------------------------------------ [2008-05-02 14:09:14] pajoye@php.net The patch to fix this special case: http://blog.thepimp.net/patches/bug44870.patch.txt ------------------------------------------------------------------------ [2008-05-02 14:08:53] derick@php.net This bug has been fixed in CVS. 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. ------------------------------------------------------------------------ [2008-04-30 14:40:16] derick@php.net On Unix: Renaming a file to a file that already exists overwrites it. Renaming a file to a directory that already exists does not write, and throws an error. Windows should obviously behave the same. ------------------------------------------------------------------------ [2008-04-30 14:17:25] pajoye@php.net "Calling rename() on a directory where there is already a file with the new name does something odd, it renames the directory but also deletes the file." Can you test it with 5.2.x please? I know that rename on windows will not rename a file when a directory already exists with the same (new) name. I'm not sure about renaming a directory. But the general idea is to replace a file if it is named using the new name (all platforms). ------------------------------------------------------------------------ [2008-04-30 14:09:56] ant@php.net Description: ------------ Calling rename() on a directory where there is already a file with the new name does something odd, it renames the directory but also deletes the file. If this is in fact a bug then the test case rename_variation3.phpt will need to be fixed up. Reproduce code: --------------- <?php $file_path = dirname(__FILE__); $filename = "$file_path/rename_variation3.tmp"; $dirname = "$file_path/rename_variation3_dir"; mkdir($dirname); $fp = fopen($filename, "w"); fclose($fp); var_dump( rename($dirname, $filename) ); echo "Done\n"; ?> Expected result: ---------------- A directory called rename_variation3.tmp and also a file called rename_variation3.tmp Actual result: -------------- A directory called rename_variation3.tmp and no file..! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44870&edit=1

« previous php.bugs (#124658) next »