#32160 [Opn]: Copying a file into itself leads to data loss

From: Date: Wed, 22 Jun 2005 16:14:11 +0000
Subject: #32160 [Opn]: Copying a file into itself leads to data loss
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-80843@lists.php.net to get a copy of this message
 ID:               32160
 Updated by:       iliaa@php.net
 Reported By:      chernyshevsky at hotmail dot com
 Status:           Open
 Bug Type:         Filesystem function related
 Operating System: *
-PHP Version:      5CVS, 4CVS (2005-06-20)
+PHP Version:      4CVS (2005-06-20)
 New Comment:

Fixed in PHP5 CVS, will be applied to 4.X tree after 4.4 release.


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

[2005-03-30 10:23:01] sniper@php.net

The patch was reverted -> re-opened.


------------------------------------------------------------------------

[2005-03-03 04:32:05] iliaa@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.



------------------------------------------------------------------------

[2005-03-02 03:20:26] chernyshevsky at hotmail dot com

Description:
------------
Copying a file into itself causes the source file to be truncate to 0
bytes.

copy("test", "test"); // test.txt -> 0

You can't avoid this problem just by comparing the filenames, since one
could be a symlink pointing to the other. The following would destroy
test1 if test2 is a link to test1:

copy("test1", "test2");



Reproduce code:
---------------
copy("test", "test");


Expected result:
----------------
Nothing happens or a file open error.

Actual result:
--------------
Contents in source file is lost.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=32160&edit=1


Thread (7 messages)

« previous php.bugs (#80843) next »