php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47126 copy() caches incorrect stat info of file-target
Submitted: 2009-01-16 12:17 UTC Modified: 2015-01-11 04:22 UTC
Votes:5
Avg. Score:3.2 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:3 (75.0%)
From: a dot u dot savchuk at gmail dot com Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 5.2.8 OS: linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-01-16 12:17 UTC] a dot u dot savchuk at gmail dot com
Description:
------------
Function copy() has a bug (or strange behavior).

When you copy file to _already_ existed file-target,
then info of this file-target will be cached before rewrite.

Workaround here is usage of clearstatcache().

Also other problem is that copy() function is not listed in list of cached functions in manual for clearstatcache().

As i understand from source code, the problem is that copy() uses php_stream_stat_path_ex() [ _php_stream_stat_path() ] function which stores stat info in cache. Correct solutions are:
1. add parameter to php_stream_stat_path_ex() to not store info to cache and call it for destination path in php_copy_file_ex()
2. clear cache after successfull call of php_stream_stat_path_ex() for destination path in php_copy_file_ex().



Reproduce code:
---------------
<?php

$source = '/t1.t';
$target = '/t2.t';

file_put_contents($source, 'aaaaaaaaaa');
file_put_contents($target, 'a');
clearstatcache( true );

copy( $source, $target );

var_dump( filesize($target) );
?>


Expected result:
----------------
int(10)


Actual result:
--------------
int(1)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-01 11:11 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-04-09 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".
 [2009-12-15 01:03 UTC] felipe@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-12-23 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".
 [2012-02-28 07:23 UTC] t dot weber at digi-info dot de
Since the original reporter doesn’t seem to be interested in it anymore, I’m 
speaking up.

This bug is still present in PHP 5.3.10.

I agree with the original reporter that the documentation should be updated. 
However, I have not looked into PHP’s source code and cannot comment on his 
proposed solution.
 [2012-03-05 13:00 UTC] raphaelm@php.net
Feedback was provided, so although this is not the category I normally work in I 
take the liberty to set this bug report to re-opened.
 [2012-03-05 13:00 UTC] raphaelm@php.net
-Status: No Feedback +Status: Re-Opened
 [2015-01-03 12:52 UTC] kassner@php.net
-Status: Re-Opened +Status: Feedback
 [2015-01-03 12:52 UTC] kassner@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.4-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Tested on 5.4.30 and 5.5.20, both returning the expected result.
 [2015-01-11 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Oct 18 16:01:28 2019 UTC