lbarnaud                Thu Aug  7 09:25:33 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/standard/tests/file    clearstatcache_001.phpt 

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/standard       basic_functions.c filestat.c php_filestat.h 
    /php-src/ext/standard/tests/file    bug39367.phpt 
                                        clearstatcache_error.phpt 
    /php-src/main/streams       plain_wrapper.c 
  Log:
  MFH:
  Added clear_realpath_cache and filename parameters to clearstatcache() (Jani,
  Arnaud)
  [DOC] clearstatcache() now defaults to not affect the realpath cache.
  clearstatcache() now takes two optionnal parameters, clear_realpath_cache to
  clear the realpath cache (defaults to false), and filename to clear only the
  given filename from the cache.
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.253&r2=1.2027.2.547.2.965.2.254&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.253 
php-src/NEWS:1.2027.2.547.2.965.2.254
--- php-src/NEWS:1.2027.2.547.2.965.2.253       Wed Aug  6 21:31:45 2008
+++ php-src/NEWS        Thu Aug  7 09:25:32 2008
@@ -2,6 +2,8 @@
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 200?, PHP 5.3.0 Alpha 2
 - Removed shebang line check from CGI sapi (it is checked by scanner) (Dmitry)
+- Added clear_realpath_cache and filename parameters to clearstatcache() (Jani,
+  Arnaud)
 
 - Added litespeed SAPI module. (George Wang)
 - Added ext/hash support to ext/session's ID generator. (Sara)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.64.2.45&r2=1.725.2.31.2.64.2.46&diff_format=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.45 
php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.46
--- php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.45 Sun Aug  3 
12:15:55 2008
+++ php-src/ext/standard/basic_functions.c      Thu Aug  7 09:25:32 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.45 2008/08/03 12:15:55 jani Exp 
$ */
+/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.46 2008/08/07 09:25:32 lbarnaud 
Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -1507,7 +1507,9 @@
 #endif
 
 static
-ZEND_BEGIN_ARG_INFO(arginfo_clearstatcache, 0)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_clearstatcache, 0, 0, 0)
+       ZEND_ARG_INFO(0, clear_realpath_cache)
+       ZEND_ARG_INFO(0, filename)
 ZEND_END_ARG_INFO()
 
 static
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/filestat.c?r1=1.136.2.8.2.14.2.6&r2=1.136.2.8.2.14.2.7&diff_format=u
Index: php-src/ext/standard/filestat.c
diff -u php-src/ext/standard/filestat.c:1.136.2.8.2.14.2.6 
php-src/ext/standard/filestat.c:1.136.2.8.2.14.2.7
--- php-src/ext/standard/filestat.c:1.136.2.8.2.14.2.6  Mon Mar 10 22:12:36 2008
+++ php-src/ext/standard/filestat.c     Thu Aug  7 09:25:33 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: filestat.c,v 1.136.2.8.2.14.2.6 2008/03/10 22:12:36 felipe Exp $ */
+/* $Id: filestat.c,v 1.136.2.8.2.14.2.7 2008/08/07 09:25:33 lbarnaud Exp $ */
 
 #include "php.h"
 #include "safe_mode.h"
@@ -712,8 +712,11 @@
 
 /* {{{ php_clear_stat_cache()
 */
-PHPAPI void php_clear_stat_cache(TSRMLS_D)
+PHPAPI void php_clear_stat_cache(zend_bool clear_realpath_cache, const char 
*filename, int filename_len TSRMLS_DC)
 {
+       /* always clear CurrentStatFile and CurrentLStatFile even if filename 
is not NULL
+        * as it may contains outdated data (e.g. "nlink" for a directory when 
deleting a file
+        * in this directory, as shown by lstat_stat_variation9.phpt) */
        if (BG(CurrentStatFile)) {
                efree(BG(CurrentStatFile));
                BG(CurrentStatFile) = NULL;
@@ -722,18 +725,29 @@
                efree(BG(CurrentLStatFile));
                BG(CurrentLStatFile) = NULL;
        }
-       realpath_cache_clean(TSRMLS_C);
+       if (clear_realpath_cache) {
+               if (filename != NULL) {
+                       realpath_cache_del(filename, filename_len TSRMLS_CC);
+               } else {
+                       realpath_cache_clean(TSRMLS_C);
+               }
+       }
 }
 /* }}} */
 
-/* {{{ proto void clearstatcache(void)
+/* {{{ proto void clearstatcache([bool clear_realpath_cache[, string 
filename]])
    Clear file stat cache */
 PHP_FUNCTION(clearstatcache)
 {
-       if (zend_parse_parameters_none() == FAILURE) {
+       zend_bool  clear_realpath_cache = 0;
+       char      *filename             = NULL;
+       int        filename_len;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bs", 
&clear_realpath_cache, &filename, &filename_len) == FAILURE) {
                return;
        }
-       php_clear_stat_cache(TSRMLS_C);
+
+       php_clear_stat_cache(clear_realpath_cache, filename, filename_len 
TSRMLS_CC);
 }
 /* }}} */
 
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/php_filestat.h?r1=1.24.2.4.2.1.2.3&r2=1.24.2.4.2.1.2.4&diff_format=u
Index: php-src/ext/standard/php_filestat.h
diff -u php-src/ext/standard/php_filestat.h:1.24.2.4.2.1.2.3 
php-src/ext/standard/php_filestat.h:1.24.2.4.2.1.2.4
--- php-src/ext/standard/php_filestat.h:1.24.2.4.2.1.2.3        Mon Dec 31 
07:17:15 2007
+++ php-src/ext/standard/php_filestat.h Thu Aug  7 09:25:33 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_filestat.h,v 1.24.2.4.2.1.2.3 2007/12/31 07:17:15 sebastian Exp $ 
*/
+/* $Id: php_filestat.h,v 1.24.2.4.2.1.2.4 2008/08/07 09:25:33 lbarnaud Exp $ */
 
 #ifndef PHP_FILESTAT_H
 #define PHP_FILESTAT_H
@@ -87,7 +87,7 @@
 typedef int php_stat_len;
 #endif
 
-PHPAPI void php_clear_stat_cache(TSRMLS_D);
+PHPAPI void php_clear_stat_cache(zend_bool clear_realpath_cache, const char 
*filename, int filename_len TSRMLS_DC);
 PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int 
type, zval *return_value TSRMLS_DC);
 
 /* Switches for various filestat functions: */
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/bug39367.phpt?r1=1.1.2.2&r2=1.1.2.2.2.1&diff_format=u
Index: php-src/ext/standard/tests/file/bug39367.phpt
diff -u php-src/ext/standard/tests/file/bug39367.phpt:1.1.2.2 
php-src/ext/standard/tests/file/bug39367.phpt:1.1.2.2.2.1
--- php-src/ext/standard/tests/file/bug39367.phpt:1.1.2.2       Wed Apr 18 
14:51:29 2007
+++ php-src/ext/standard/tests/file/bug39367.phpt       Thu Aug  7 09:25:33 2008
@@ -19,7 +19,7 @@
   echo file_get_contents('/tmp/1link')."\n";
 
   unlink('/tmp/1link');
-  clearstatcache();
+  clearstatcache(true);
 
   echo file_get_contents('/tmp/1link')."\n";
 
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/clearstatcache_error.phpt?r1=1.1.2.1.2.2&r2=1.1.2.1.2.3&diff_format=u
Index: php-src/ext/standard/tests/file/clearstatcache_error.phpt
diff -u php-src/ext/standard/tests/file/clearstatcache_error.phpt:1.1.2.1.2.2 
php-src/ext/standard/tests/file/clearstatcache_error.phpt:1.1.2.1.2.3
--- php-src/ext/standard/tests/file/clearstatcache_error.phpt:1.1.2.1.2.2       
Mon Mar 10 22:17:59 2008
+++ php-src/ext/standard/tests/file/clearstatcache_error.phpt   Thu Aug  7 
09:25:33 2008
@@ -3,17 +3,17 @@
 --FILE--
 <?php
 /*
-   Prototype: void clearstatcache (void);
+   Prototype: void clearstatcache ([bool clear_realpath_cache[, filename]]);
    Description: clears files status cache
 */
 
 echo "*** Testing clearstatcache() function: error conditions ***\n";
-var_dump( clearstatcache("file") );  //No.of args more than expected
+var_dump( clearstatcache(0, "/foo/bar", 1) );  //No.of args more than expected
 echo "*** Done ***\n";
 ?>
 --EXPECTF--
 *** Testing clearstatcache() function: error conditions ***
 
-Warning: clearstatcache() expects exactly 0 parameters, 1 given in %s on line 
%d
+Warning: clearstatcache() expects at most 2 parameters, 3 given in %s on line 
%d
 NULL
 *** Done ***
http://cvs.php.net/viewvc.cgi/php-src/main/streams/plain_wrapper.c?r1=1.52.2.6.2.23.2.7&r2=1.52.2.6.2.23.2.8&diff_format=u
Index: php-src/main/streams/plain_wrapper.c
diff -u php-src/main/streams/plain_wrapper.c:1.52.2.6.2.23.2.7 
php-src/main/streams/plain_wrapper.c:1.52.2.6.2.23.2.8
--- php-src/main/streams/plain_wrapper.c:1.52.2.6.2.23.2.7      Sun Apr 13 
22:19:10 2008
+++ php-src/main/streams/plain_wrapper.c        Thu Aug  7 09:25:33 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: plain_wrapper.c,v 1.52.2.6.2.23.2.7 2008/04/13 22:19:10 cellog Exp $ */
+/* $Id: plain_wrapper.c,v 1.52.2.6.2.23.2.8 2008/08/07 09:25:33 lbarnaud Exp $ 
*/
 
 #include "php.h"
 #include "php_globals.h"
@@ -1039,8 +1039,8 @@
                return 0;
        }
 
-       /* Clear stat cache */
-       php_clear_stat_cache(TSRMLS_C);
+       /* Clear stat cache (and realpath cache) */
+       php_clear_stat_cache(1, NULL, 0 TSRMLS_CC);
 
        return 1;
 }
@@ -1111,8 +1111,8 @@
         return 0;
        }
 
-       /* Clear stat cache */
-       php_clear_stat_cache(TSRMLS_C);
+       /* Clear stat cache (and realpath cache) */
+       php_clear_stat_cache(1, NULL, 0 TSRMLS_CC);
 
        return 1;
 }
@@ -1225,8 +1225,8 @@
                return 0;
        }
 
-       /* Clear stat cache */
-       php_clear_stat_cache(TSRMLS_C);
+       /* Clear stat cache (and realpath cache) */
+       php_clear_stat_cache(1, NULL, 0 TSRMLS_CC);
 
        return 1;
 }

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/clearstatcache_001.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/file/clearstatcache_001.phpt
+++ php-src/ext/standard/tests/file/clearstatcache_001.phpt
--TEST--
clearstatcache() optionnal parameters
--SKIPIF--
<?php
if (strncmp(PHP_OS, "WIN", 3) === 0) {
    die('skip not for Windows');
}
?>
--FILE--
<?php

@rmdir(__FILE__ . "_dir1");
@rmdir(__FILE__ . "_dir2");
@unlink(__FILE__ . "_link1");
@unlink(__FILE__ . "_link2");

mkdir(__FILE__ . "_dir1");
mkdir(__FILE__ . "_dir2");
symlink(__FILE__ . "_link1", __FILE__ . "_link2");
symlink(__FILE__ . "_dir1", __FILE__ . "_link1");

var_dump(realpath(__FILE__ . "_link2"));
passthru("rm -f " . escapeshellarg(__FILE__ . "_link1"));
var_dump(realpath(__FILE__ . "_link2"));
clearstatcache(false);
var_dump(realpath(__FILE__ . "_link2"));
clearstatcache(true, "/foo/bar");
var_dump(realpath(__FILE__ . "_link2"));
clearstatcache(true, __FILE__ . "_link2");
var_dump(realpath(__FILE__ . "_link2"));

?>
--CLEAN--
<?php
@rmdir(__FILE__ . "_dir1");
@rmdir(__FILE__ . "_dir2");
@unlink(__FILE__ . "_link1");
@unlink(__FILE__ . "_link2");
?>
--EXPECTF--
%unicode|string%(%d) "%s_dir1"
%unicode|string%(%d) "%s_dir1"
%unicode|string%(%d) "%s_dir1"
%unicode|string%(%d) "%s_dir1"
bool(false)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to