24
24
class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
25
25
{
26
26
private bool $ ignoreUnreadableDirs ;
27
+ private bool $ ignoreFirstRewind = true ;
27
28
private ?bool $ rewindable = null ;
28
29
29
30
// these 3 properties take part of the performance optimization to avoid redoing the same work in all iterations
@@ -102,7 +103,6 @@ public function getChildren(): \RecursiveDirectoryIterator
102
103
$ children ->ignoreUnreadableDirs = $ this ->ignoreUnreadableDirs ;
103
104
104
105
// performance optimization to avoid redoing the same work in all children
105
- $ children ->rewindable = &$ this ->rewindable ;
106
106
$ children ->rootPath = $ this ->rootPath ;
107
107
}
108
108
@@ -112,36 +112,23 @@ public function getChildren(): \RecursiveDirectoryIterator
112
112
}
113
113
}
114
114
115
- /**
116
- * Do nothing for non rewindable stream.
117
- */
118
- public function rewind (): void
115
+ public function next (): void
119
116
{
120
- if (false === $ this ->isRewindable ()) {
121
- return ;
122
- }
117
+ $ this ->ignoreFirstRewind = false ;
123
118
124
- parent ::rewind ();
119
+ parent ::next ();
125
120
}
126
121
127
- /**
128
- * Checks if the stream is rewindable.
129
- */
130
- public function isRewindable (): bool
122
+ public function rewind (): void
131
123
{
132
- if (null !== $ this ->rewindable ) {
133
- return $ this ->rewindable ;
134
- }
135
-
136
- if (false !== $ stream = @opendir ($ this ->getPath ())) {
137
- $ infos = stream_get_meta_data ($ stream );
138
- closedir ($ stream );
124
+ // some streams like FTP are not rewindable, ignore the first rewind after creation,
125
+ // as newly created DirectoryIterator does not need to be rewound
126
+ if ($ this ->ignoreFirstRewind ) {
127
+ $ this ->ignoreFirstRewind = false ;
139
128
140
- if ($ infos ['seekable ' ]) {
141
- return $ this ->rewindable = true ;
142
- }
129
+ return ;
143
130
}
144
131
145
- return $ this -> rewindable = false ;
132
+ parent :: rewind () ;
146
133
}
147
134
}
0 commit comments