colder Tue Jul 8 22:40:49 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/spl spl_directory.c /php-src/ext/spl/tests dit_001.phpt fileobject_003.phpt fileobject_getfileinfo_basic.phpt Log: MFH: - Fix filename in debug_info - Fix #45345 (getPathInfo on the file instead of the dir) - Remove trailing / on input
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.45.2.27.2.23.2.23&r2=1.45.2.27.2.23.2.24&diff_format=u Index: php-src/ext/spl/spl_directory.c diff -u php-src/ext/spl/spl_directory.c:1.45.2.27.2.23.2.23 php-src/ext/spl/spl_directory.c:1.45.2.27.2.23.2.24 --- php-src/ext/spl/spl_directory.c:1.45.2.27.2.23.2.23 Wed Jul 2 10:47:11 2008 +++ php-src/ext/spl/spl_directory.c Tue Jul 8 22:40:48 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_directory.c,v 1.45.2.27.2.23.2.23 2008/07/02 10:47:11 tony2001 Exp $ */ +/* $Id: spl_directory.c,v 1.45.2.27.2.23.2.24 2008/07/08 22:40:48 colder Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -347,17 +347,23 @@ intern->file_name = use_copy ? estrndup(path, len) : path; intern->file_name_len = len; - p1 = strrchr(path, '/'); + while(IS_SLASH_AT(intern->file_name, intern->file_name_len-1)) { + intern->file_name[intern->file_name_len-1] = 0; + intern->file_name_len--; + } + + p1 = strrchr(intern->file_name, '/'); #if defined(PHP_WIN32) || defined(NETWARE) - p2 = strrchr(path, '\\'); + p2 = strrchr(intern->file_name, '\\'); #else p2 = 0; #endif if (p1 || p2) { - intern->_path_len = (p1 > p2 ? p1 : p2) - path; + intern->_path_len = (p1 > p2 ? p1 : p2) - intern->file_name; } else { intern->_path_len = 0; } + intern->_path = estrndup(path, intern->_path_len); } /* }}} */ @@ -499,7 +505,25 @@ } /* }}} */ -static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp TSRMLS_DC) /* {{{{ */ +static char *spl_filesystem_object_get_pathname(spl_filesystem_object *intern, int *len TSRMLS_DC) { /* {{{ */ + switch (intern->type) { + case SPL_FS_INFO: + case SPL_FS_FILE: + *len = intern->file_name_len; + return intern->file_name; + case SPL_FS_DIR: + if (intern->u.dir.entry.d_name[0]) { + spl_filesystem_object_get_file_name(intern TSRMLS_CC); + *len = intern->file_name_len; + return intern->file_name; + } + } + *len = 0; + return NULL; +} +/* }}} */ + +static HashTable* spl_filesystem_object_get_debug_info(zval *obj, int *is_temp TSRMLS_DC) /* {{{ */ { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(obj TSRMLS_CC); HashTable *rv; @@ -518,13 +542,20 @@ zend_hash_copy(rv, intern->std.properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - path = spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC); pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "pathName", sizeof("pathName")-1, &pnlen TSRMLS_CC); + path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC); add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, path, path_len, 1); efree(pnstr); + if (intern->file_name) { pnstr = spl_gen_private_prop_name(spl_ce_SplFileInfo, "fileName", sizeof("fileName")-1, &pnlen TSRMLS_CC); - add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->file_name, intern->file_name_len, 1); + spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC); + + if (path_len && path_len < intern->file_name_len) { + add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->file_name + path_len + 1, intern->file_name_len - (path_len + 1), 1); + } else { + add_assoc_stringl_ex(&zrv, pnstr, pnlen+1, intern->file_name, intern->file_name_len, 1); + } efree(pnstr); } if (intern->type == SPL_FS_DIR) { @@ -560,7 +591,7 @@ return rv; } -/* }}}} */ +/* }}} */ #define DIT_CTOR_FLAGS 0x00000001 #define DIT_CTOR_GLOB 0x00000002 @@ -775,18 +806,14 @@ SPL_METHOD(SplFileInfo, getPathname) { spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - switch (intern->type) { - case SPL_FS_INFO: - case SPL_FS_FILE: - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); - case SPL_FS_DIR: - if (intern->u.dir.entry.d_name[0]) { - spl_filesystem_object_get_file_name(intern TSRMLS_CC); - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); - } + char *path; + int path_len; + path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC); + if (path != NULL) { + RETURN_STRINGL(path, path_len, 1); + } else { + RETURN_FALSE; } - RETURN_BOOL(0); } /* }}} */ @@ -1092,8 +1119,10 @@ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { int path_len; - char *path = spl_filesystem_object_get_path(intern, &path_len TSRMLS_CC); - spl_filesystem_object_create_info(intern, path, path_len, 1, ce, return_value TSRMLS_CC); + char *path = spl_filesystem_object_get_pathname(intern, &path_len TSRMLS_CC); + if (path) { + spl_filesystem_object_create_info(intern, path, path_len, 1, ce, return_value TSRMLS_CC); + } } php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/dit_001.phpt?r1=1.3.6.4&r2=1.3.6.5&diff_format=u Index: php-src/ext/spl/tests/dit_001.phpt diff -u php-src/ext/spl/tests/dit_001.phpt:1.3.6.4 php-src/ext/spl/tests/dit_001.phpt:1.3.6.5 --- php-src/ext/spl/tests/dit_001.phpt:1.3.6.4 Sat May 24 14:10:43 2008 +++ php-src/ext/spl/tests/dit_001.phpt Tue Jul 8 22:40:48 2008 @@ -10,9 +10,11 @@ ?> ===DONE=== --EXPECTF-- -object(DirectoryIterator)#%d (3) { +object(DirectoryIterator)#%d (4) { %s"pathName"%s"SplFileInfo":private]=> - %s(1) "." + %s(%d) "./%s" + %s"fileName"%s"SplFileInfo":private]=> + %s(%d) "%s" %s"glob"%s"DirectoryIterator":private]=> bool(false) %s"subPathName"%s"RecursiveDirectoryIterator":private]=> http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/fileobject_003.phpt?r1=1.1.2.5.2.2&r2=1.1.2.5.2.3&diff_format=u Index: php-src/ext/spl/tests/fileobject_003.phpt diff -u php-src/ext/spl/tests/fileobject_003.phpt:1.1.2.5.2.2 php-src/ext/spl/tests/fileobject_003.phpt:1.1.2.5.2.3 --- php-src/ext/spl/tests/fileobject_003.phpt:1.1.2.5.2.2 Sat May 24 14:10:44 2008 +++ php-src/ext/spl/tests/fileobject_003.phpt Tue Jul 8 22:40:48 2008 @@ -47,13 +47,13 @@ ["pathName":"SplFileInfo":private]=> string(%d) "%s" ["fileName":"SplFileInfo":private]=> - string(%d) "%sfileobject_001a.txt" + string(%d) "fileobject_001a.txt" } object(SplFileInfo)#%d (2) { ["pathName":"SplFileInfo":private]=> string(%d) "%s" ["fileName":"SplFileInfo":private]=> - string(%d) "%sfileobject_001a.txt" + string(%d) "fileobject_001a.txt" } bool(false) bool(true) @@ -92,8 +92,8 @@ string(%d) "%sspl" bool(true) string(%d) "%stests" -string(%d) "%stests" -string(%d) "%stests" +string(%d) "tests" +string(%d) "%sspl" ===2=== object(SplFileInfo)#%d (2) { ["pathName":"SplFileInfo":private]=> http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt?r1=1.1.2.2&r2=1.1.2.3&diff_format=u Index: php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt diff -u php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt:1.1.2.2 php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt:1.1.2.3 --- php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt:1.1.2.2 Thu Jun 12 20:46:12 2008 +++ php-src/ext/spl/tests/fileobject_getfileinfo_basic.phpt Tue Jul 8 22:40:48 2008 @@ -14,20 +14,31 @@ $d = new SplFileInfo( __DIR__ ); echo "\n"; var_dump($fi = $d->getFileInfo(), (string)$fi); +$d = new SplFileInfo( __DIR__."/" ); +echo "\n"; +var_dump($fi = $d->getFileInfo(), (string)$fi); ?> --EXPECTF-- -object(SplFileInfo)#2 (2) { +object(SplFileInfo)#%d (2) { ["pathName":"SplFileInfo":private]=> - string(%d) "%sext%espl%etests" - ["fileName":"SplFileInfo":private]=> string(%d) "%sext%espl%etests%efileobject_getfileinfo_basic.php" + ["fileName":"SplFileInfo":private]=> + string(%d) "fileobject_getfileinfo_basic.php" } string(%d) "%sext%espl%etests%efileobject_getfileinfo_basic.php" -object(SplFileInfo)#4 (2) { +object(SplFileInfo)#%d (2) { ["pathName":"SplFileInfo":private]=> - string(%d) "%sext%espl" + string(%d) "%sext%espl%etests" ["fileName":"SplFileInfo":private]=> + string(%d) "tests" +} +string(%d) "%sext%espl%etests" + +object(SplFileInfo)#%d (2) { + ["pathName":"SplFileInfo":private]=> string(%d) "%sext%espl%etests" + ["fileName":"SplFileInfo":private]=> + string(%d) "tests" } string(%d) "%sext%espl%etests"
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php