Fixed bug #48788 (RecursiveDirectoryIterator doesn't descend into symlinked

directories).

[DOC]

To avoid breaking how existing code works a new constant is introduced for
the RecursiveDirectoryIterator() that directs the code to follow symlinks.
This constant RecursiveDirectoryIterator::FOLLOW_SYMLINKS can be passed a
flag to the constructor to trigger symlink following.
This commit is contained in:
Ilia Alshanetsky 2009-07-08 03:06:59 +00:00
parent 2331863a5c
commit c16b7585f6
3 changed files with 5 additions and 1 deletions

2
NEWS
View File

@ -4,6 +4,8 @@ PHP NEWS
- Fixed spl_autoload_unregister/spl_autoad_functions wrt. Closures and
Functors. (Christian Seiler)
- Fixed bug #48788 (RecursiveDirectoryIterator doesn't descend into symlinked
directories). (Ilia)
- Fixed bug #48771 (rename() between volumes fails and reports no error on
Windows). (Pierre)
- Fixed bug #48757 (ReflectionFunction::invoke() parameter issues). (Kalle)

View File

@ -1246,7 +1246,7 @@ SPL_METHOD(RecursiveDirectoryIterator, hasChildren)
return;
}
spl_filesystem_object_get_file_name(intern TSRMLS_CC);
if (!allow_links) {
if (!allow_links && !(intern->flags & SPL_FILE_DIR_FOLLOW_SYMLINKS)) {
php_stat(intern->file_name, intern->file_name_len, FS_IS_LINK, return_value TSRMLS_CC);
if (zend_is_true(return_value)) {
RETURN_FALSE;
@ -2656,6 +2656,7 @@ PHP_MINIT_FUNCTION(spl_directory)
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "CURRENT_AS_SELF", SPL_FILE_DIR_CURRENT_AS_SELF);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "KEY_MODE_MASK", SPL_FILE_DIR_KEY_MODE_MASK);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "KEY_AS_PATHNAME", SPL_FILE_DIR_KEY_AS_PATHNAME);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "FOLLOW_SYMLINKS", SPL_FILE_DIR_FOLLOW_SYMLINKS);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "KEY_AS_FILENAME", SPL_FILE_DIR_KEY_AS_FILENAME);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "NEW_CURRENT_AND_KEY", SPL_FILE_DIR_KEY_AS_FILENAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, "SKIP_DOTS", SPL_FILE_DIR_SKIPDOTS);

View File

@ -129,6 +129,7 @@ static inline spl_filesystem_object* spl_filesystem_iterator_to_object(spl_files
#define SPL_FILE_DIR_KEY_AS_PATHNAME 0x00000000 /* make RecursiveDirectoryTree::key() return getPathname() */
#define SPL_FILE_DIR_KEY_AS_FILENAME 0x00000100 /* make RecursiveDirectoryTree::key() return getFilename() */
#define SPL_FILE_DIR_FOLLOW_SYMLINKS 0x00000200 /* make RecursiveDirectoryTree::hasChildren() follow symlinks */
#define SPL_FILE_DIR_KEY_MODE_MASK 0x00000F00 /* mask RecursiveDirectoryTree::key() */
#define SPL_FILE_DIR_KEY(intern,mode) ((intern->flags&SPL_FILE_DIR_KEY_MODE_MASK)==mode)