colder Tue May 20 21:46:14 2008 UTC
Added files:
/php-src/ext/spl/tests fileobject_004.phpt
Modified files:
/php-src/ext/spl spl_directory.c spl_directory.h
Log:
Fix path lookup when include_path is used
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.154&r2=1.155&diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.154
php-src/ext/spl/spl_directory.c:1.155
--- php-src/ext/spl/spl_directory.c:1.154 Fri May 16 13:22:02 2008
+++ php-src/ext/spl/spl_directory.c Tue May 20 21:46:13 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_directory.c,v 1.154 2008/05/16 13:22:02 colder Exp $ */
+/* $Id: spl_directory.c,v 1.155 2008/05/20 21:46:13 colder Exp $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -109,6 +109,9 @@
if (intern->u.file.open_mode) {
efree(intern->u.file.open_mode);
}
+ if (intern->orig_path) {
+ efree(intern->orig_path);
+ }
}
spl_filesystem_file_free_line(intern TSRMLS_CC);
break;
@@ -277,6 +280,10 @@
intern->file_name_len--;
}
+ /* NOTE: Works as long as stream->orig_path is not unicode aware, might
+ * break later. */
+ intern->orig_path = estrndup(intern->u.file.stream->orig_path,
strlen(intern->u.file.stream->orig_path));
+
intern->file_name = ezstrndup(intern->file_name_type,
intern->file_name, intern->file_name_len);
intern->u.file.open_mode = estrndup(intern->u.file.open_mode,
intern->u.file.open_mode_len);
@@ -1082,10 +1089,14 @@
spl_filesystem_object_get_file_name(intern TSRMLS_CC);
}
- if (intern->file_name_type == IS_UNICODE) {
- php_stream_path_encode(NULL, &filename, &filename_len,
intern->file_name.u, intern->file_name_len, REPORT_ERRORS, FG(default_context));
+ if (intern->orig_path) {
+ filename = intern->orig_path;
} else {
- filename = intern->file_name.s;
+ if (intern->file_name_type == IS_UNICODE) {
+ php_stream_path_encode(NULL, &filename, &filename_len,
intern->file_name.u, intern->file_name_len, REPORT_ERRORS, FG(default_context));
+ } else {
+ filename = intern->file_name.s;
+ }
}
if (filename && VCWD_REALPATH(filename, buff)) {
@@ -1994,6 +2005,8 @@
spl_filesystem_object *intern =
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
zend_bool use_include_path = 0;
zstr p1, p2;
+ char *tmp_path;
+ int tmp_path_len;
php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC);
@@ -2009,31 +2022,31 @@
}
if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) ==
SUCCESS) {
- if (intern->file_name_type == IS_UNICODE) {
- p1.u = u_strrchr(intern->file_name.u, '/');
- } else {
- p1.s = strrchr(intern->file_name.s, '/');
+ tmp_path_len = strlen(intern->u.file.stream->orig_path);
+
+ if (tmp_path_len && IS_SLASH_AT(IS_STRING,
ZSTR(intern->u.file.stream->orig_path), tmp_path_len-1)) {
+ tmp_path_len--;
}
+
+ tmp_path = estrndup(intern->u.file.stream->orig_path,
tmp_path_len);
+
+ p1.s = strrchr(tmp_path, '/');
#if defined(PHP_WIN32) || defined(NETWARE)
- if (intern->file_name_type == IS_UNICODE) {
- p2.u = u_strrchr(intern->file_name.u, '\\');
- } else {
- p2.s = strrchr(intern->file_name.s, '\\');
- }
+ p2.s = strrchr(tmp_path, '\\');
#else
p2.v = 0;
#endif
+
if (p1.v || p2.v) {
- if (intern->file_name_type == IS_UNICODE) {
- intern->_path_len = (p1.u > p2.u ? p1.u : p2.u)
- intern->file_name.u;
- } else {
- intern->_path_len = (p1.s > p2.s ? p1.s : p2.s)
- intern->file_name.s;
- }
+ intern->_path_len = (p1.s > p2.s ? p1.s : p2.s) -
tmp_path;
} else {
intern->_path_len = 0;
}
- intern->_path_type = intern->file_name_type;
- intern->_path = ezstrndup(intern->file_name_type,
intern->file_name, intern->_path_len);
+
+ efree(tmp_path);
+
+ intern->_path =
ZSTR(estrndup(intern->u.file.stream->orig_path, intern->_path_len));
+ intern->_path_type = IS_STRING;
}
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.h?r1=1.43&r2=1.44&diff_format=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.43
php-src/ext/spl/spl_directory.h:1.44
--- php-src/ext/spl/spl_directory.h:1.43 Fri May 16 13:22:02 2008
+++ php-src/ext/spl/spl_directory.h Tue May 20 21:46:13 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_directory.h,v 1.43 2008/05/16 13:22:02 colder Exp $ */
+/* $Id: spl_directory.h,v 1.44 2008/05/20 21:46:13 colder Exp $ */
#ifndef SPL_DIRECTORY_H
#define SPL_DIRECTORY_H
@@ -65,6 +65,7 @@
zend_uchar _path_type;
zstr _path;
int _path_len;
+ char *orig_path;
zend_uchar file_name_type;
zstr file_name;
int file_name_len;
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/fileobject_004.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/fileobject_004.phpt
+++ php-src/ext/spl/tests/fileobject_004.phpt
--TEST--
SPL: SplFileObject realpath and include_path
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php
set_include_path('tests');
chdir(dirname(dirname(__FILE__))); // ext/spl
$fo = new SplFileObject('fileobject_004.phpt', 'r', true);
var_dump($fo->getPath());
var_dump($fo->getFilename());
var_dump($fo->getRealPath());
?>
==DONE==
--EXPECTF--
string(%d) "%sspl%stests"
string(19) "fileobject_004.phpt"
string(%d) "%sspl%stests%sfileobject_004.phpt"
==DONE==
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php