#44805 [Asn->Csd]: rename() function is not portable to Windows
| From: | dmitry@php.net | Date: | Thu, 24 Apr 2008 07:53:50 +0000 |
| Subject: | #44805 [Asn->Csd]: rename() function is not portable to Windows | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-124464@lists.php.net to get a copy of this message | ||
ID: 44805
Updated by: dmitry@php.net
Reported By: rasmus at mindplay dot dk
-Status: Assigned
+Status: Closed
Bug Type: Filesystem function related
Operating System: WindowsXP/DebianLinux
PHP Version: 5.2.5
Assigned To: dmitry
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-04-23 14:21:35] pajoye@php.net
For the record here:
http://blog.thepimp.net/patches/TSRM_windows_rename.patch.txt
http://blog.thepimp.net/patches/bug44805.phpt
It fixes this issue. Dmitry will commit it in the next couple of days.
Assigned to Dmitry.
------------------------------------------------------------------------
[2008-04-23 07:36:25] pajoye@php.net
That's correct. We already uses MoveFileEx in ext/zip (prooving that it
is well supported by the current php windows setup).
Patch + tests will come shortly.
------------------------------------------------------------------------
[2008-04-23 06:57:32] rasmus at mindplay dot dk
File rename with overwrite code for Windows here:
http://rikkus.info/rename-with-overwrite-on-windows.html
------------------------------------------------------------------------
[2008-04-23 06:53:09] rasmus at mindplay dot dk
Description:
------------
The behavior of rename() is inconsistent between Linux and Windows.
On Linux, the rename() function is atomic - you can rename() one file
over an existing file, and the replacement is atomic.
On Windows, you cannot rename over an existing file.
Reproduce code:
---------------
<?php
file_put_contents("file1.txt", "this is file 1");
file_put_contents("file2.txt", "this is file 2");
rename("file1.txt", "file2.txt");
echo "reading file 2: ";
readfile("file2.txt");
?>
Expected result:
----------------
reading file 2: this is file 1
Actual result:
--------------
On Linux: (CORRECT)
reading file 2: this is file 1
On Windows: (INCORRECT)
Warning: rename(file1.txt,file2.txt) [function.rename]: File exists in
C:\Web3\test\rename\test.php on line 6
reading file 2: this is file 2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44805&edit=1