@@ -202,25 +202,25 @@ PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, size_
202
202
203
203
static inline int spl_filesystem_object_get_file_name (spl_filesystem_object * intern ) /* {{{ */
204
204
{
205
- char slash = SPL_HAS_FLAG (intern -> flags , SPL_FILE_DIR_UNIXPATHS ) ? '/' : DEFAULT_SLASH ;
205
+ if (intern -> file_name ) {
206
+ /* already known */
207
+ return SUCCESS ;
208
+ }
206
209
207
210
switch (intern -> type ) {
208
211
case SPL_FS_INFO :
209
212
case SPL_FS_FILE :
210
- if (!intern -> file_name ) {
211
- zend_throw_error (NULL , "Object not initialized" );
212
- return FAILURE ;
213
- }
213
+ zend_throw_error (NULL , "Object not initialized" );
214
+ return FAILURE ;
214
215
break ;
215
216
case SPL_FS_DIR :
216
217
{
217
218
size_t name_len ;
218
219
size_t path_len = 0 ;
219
- char * path = spl_filesystem_object_get_path (intern , & path_len );
220
+ char * path ;
221
+ char slash = SPL_HAS_FLAG (intern -> flags , SPL_FILE_DIR_UNIXPATHS ) ? '/' : DEFAULT_SLASH ;
220
222
221
- if (intern -> file_name ) {
222
- zend_string_release (intern -> file_name );
223
- }
223
+ path = spl_filesystem_object_get_path (intern , & path_len );
224
224
/* if there is parent path, amend it, otherwise just use the given path as is */
225
225
name_len = strlen (intern -> u .dir .entry .d_name );
226
226
if (path_len == 0 ) {
@@ -241,6 +241,11 @@ static inline int spl_filesystem_object_get_file_name(spl_filesystem_object *int
241
241
242
242
static int spl_filesystem_dir_read (spl_filesystem_object * intern ) /* {{{ */
243
243
{
244
+ if (intern -> file_name ) {
245
+ /* invalidate */
246
+ zend_string_release (intern -> file_name );
247
+ intern -> file_name = NULL ;
248
+ }
244
249
if (!intern -> u .dir .dirp || !php_stream_readdir (intern -> u .dir .dirp , & intern -> u .dir .entry )) {
245
250
intern -> u .dir .entry .d_name [0 ] = '\0' ;
246
251
return 0 ;
0 commit comments