php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29257 breaking copy file to the same
Submitted: 2004-07-19 15:06 UTC Modified: 2004-08-01 01:00 UTC
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: zet at male dot ru Assigned:
Status: No Feedback Package: *Directory/Filesystem functions
PHP Version: 4.3.7 OS: Windows XP SP1
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: zet at male dot ru
New email:
PHP Version: OS:

 

 [2004-07-19 15:06 UTC] zet at male dot ru
Description:
------------
When i copy file with function copy, like this
copy("C:\file.gif", "C:\file.gif"), file was break. His size is 0. 

Reproduce code:
---------------
copy("C:\file.gif", "C:\file.gif");

Expected result:
----------------
IMHO file must stand without changes.

Actual result:
--------------
File changed. His size is 0.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-20 02:47 UTC] iliaa@php.net
what happens if you do: 
copy("C:\\file.gif", "C:\\file.gif") 
 [2004-08-01 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-01-14 21:40 UTC] chernyshevsky at hotmail dot com
How come no one is looking into this? It's reproducible on Linux as well. 

copy("test.txt", "test.txt") -> 0 bytes

You can't avoid this problem just by checking the filename, since one could be a symlink pointing to the other. It would introduce platform dependency as well (case-insensitivity on Windows).
 [2005-02-11 07:04 UTC] nasheet at hotmail dot com
Reproducible with Windows and Linux, looks like platform independant:

copy("/tmp/sess_1151d8174614735db903faef81b4fae0","/tmp/sess_1151d8174614735db903faef81b4fae0");

Actual result:
--------------
File changed to 0 bytes.
 [2005-07-29 04:45 UTC] richard dot managh at gmail dot com
Same behaviour here, on winxp with php4 and debian with php5, seems conceptually wrong, I would report the exact versions but it would seem this behaviour is constant on every version. Where is the sanity in truncating a file to 0 bytes if the code attempts to copy it over itself? Should preferably check for equivalent filepaths and not perform the copy function, or at least report a warning that the files were the same, both command line copy and cp (win and linux) do that.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 16:01:31 2025 UTC