php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44870 rename() on directory deletes same named file
Submitted: 2008-04-30 14:09 UTC Modified: 2008-05-02 14:18 UTC
From: ant@php.net Assigned: pajoye (profile)
Status: Closed Package: Streams related
PHP Version: 5.3CVS-2008-04-30 (snap) OS: Windows/XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ant@php.net
New email:
PHP Version: OS:

 

 [2008-04-30 14:09 UTC] 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..!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-30 14:17 UTC] 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:40 UTC] 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-05-02 14:08 UTC] 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-05-02 14:09 UTC] pajoye@php.net
The patch to fix this special case:

http://blog.thepimp.net/patches/bug44870.patch.txt
 [2008-05-02 14:18 UTC] 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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 10:01:27 2024 UTC