@@ -155,24 +155,27 @@ public function touch($files, $time = null, $atime = null)
155
155
*/
156
156
public function remove ($ files )
157
157
{
158
- $ files = iterator_to_array ($ this ->toIterator ($ files ));
158
+ if ($ files instanceof \Traversable) {
159
+ $ files = iterator_to_array ($ files , false );
160
+ } elseif (!is_array ($ files )) {
161
+ $ files = array ($ files );
162
+ }
159
163
$ files = array_reverse ($ files );
160
164
foreach ($ files as $ file ) {
161
- if (@(unlink ($ file ) || rmdir ($ file ))) {
162
- continue ;
163
- }
164
165
if (is_link ($ file )) {
165
166
// See https://bugs.php.net/52176
166
- $ error = error_get_last ();
167
- throw new IOException (sprintf ('Failed to remove symlink "%s": %s. ' , $ file , $ error ['message ' ]));
167
+ if (!@(unlink ($ file ) || '\\' !== DIRECTORY_SEPARATOR || rmdir ($ file )) && file_exists ($ file )) {
168
+ $ error = error_get_last ();
169
+ throw new IOException (sprintf ('Failed to remove symlink "%s": %s. ' , $ file , $ error ['message ' ]));
170
+ }
168
171
} elseif (is_dir ($ file )) {
169
- $ this ->remove (new \FilesystemIterator ($ file ));
172
+ $ this ->remove (new \FilesystemIterator ($ file, \FilesystemIterator:: CURRENT_AS_PATHNAME | \FilesystemIterator:: SKIP_DOTS ));
170
173
171
- if (!@rmdir ($ file )) {
174
+ if (!@rmdir ($ file ) && file_exists ( $ file ) ) {
172
175
$ error = error_get_last ();
173
176
throw new IOException (sprintf ('Failed to remove directory "%s": %s. ' , $ file , $ error ['message ' ]));
174
177
}
175
- } elseif (file_exists ($ file )) {
178
+ } elseif (!@ unlink ( $ file ) && file_exists ($ file )) {
176
179
$ error = error_get_last ();
177
180
throw new IOException (sprintf ('Failed to remove file "%s": %s. ' , $ file , $ error ['message ' ]));
178
181
}
0 commit comments