Bug #63473 [Com]: rename rename

From: Date: Fri, 09 Nov 2012 18:39:01 +0000
Subject: Bug #63473 [Com]: rename rename
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-174605@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63473&edit=1 ID: 63473 Comment by: anon at anon dot anon Reported by: anon at anon dot anon Summary: rename rename Status: Open Type: Bug Package: Filesystem function related PHP Version: 5.4.8 Block user comment: N Private report: N New Comment: Apparently PHP doesn't even have a way to merely rename a file. Using file_exists with rename will be vulnerable to race conditions (potential file overwrites) with other processes. Previous Comments: ------------------------------------------------------------------------ [2012-11-09 18:32:42] anon at anon dot anon Description: ------------ The rename function overwrites. This is totally unexpected and unintuitive behavior which could cause data loss, and it is not even documented. Combined with the fact that the rename function can "rename" across drives, it's obviously a move, not a rename. Then it should be called move, so you can tell what it does. Test script: --------------- <?php file_put_contents('1.txt', 'one'); file_put_contents('2.txt', 'two'); rename('2.txt', '1.txt'); echo '1.txt:' . file_get_contents('1.txt'); echo '2.txt:' . file_get_contents('2.txt'); Expected result: ---------------- 1.txt:one 2.txt:two plus an error that the name exists Actual result: -------------- 1.txt:two 2.txt: plus an error that 2.txt does not exist ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63473&edit=1

« previous php.bugs (#174605) next »