note 88226 added to function.copy
| From: | a dot u dot savchuk at gmail dot com | Date: | Fri, 16 Jan 2009 09:09:54 +0000 |
| Subject: | note 88226 added to function.copy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149306@lists.php.net to get a copy of this message | ||
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.
So, for example, result of 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) );
------------------
will be:
------------------
int(1)
------------------
instead of expected:
------------------
int(10)
------------------
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().
I hope this info will help.
P.S.: 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().
----
Server IP: 69.147.83.197
Probable Submitter: 195.82.157.101
----
Manual Page -- http://www.php.net/manual/en/function.copy.php
Edit -- https://master.php.net/note/edit/88226
Del: integrated -- https://master.php.net/note/delete/88226/integrated
Del: useless -- https://master.php.net/note/delete/88226/useless
Del: bad code -- https://master.php.net/note/delete/88226/bad+code
Del: spam -- https://master.php.net/note/delete/88226/spam
Del: non-english -- https://master.php.net/note/delete/88226/non-english
Del: in docs -- https://master.php.net/note/delete/88226/in+docs
Del: other reasons-- https://master.php.net/note/delete/88226
Reject -- https://master.php.net/note/reject/88226
Search -- https://master.php.net/manage/user-notes.php