@@ -155,24 +155,28 @@ 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 ));
170
-
171
172
if (!@rmdir ($ file )) {
173
+ $ this ->remove (new \FilesystemIterator ($ file , \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS ));
174
+ }
175
+ if (!@rmdir ($ file ) && file_exists ($ file )) {
172
176
$ error = error_get_last ();
173
177
throw new IOException (sprintf ('Failed to remove directory "%s": %s. ' , $ file , $ error ['message ' ]));
174
178
}
175
- } elseif (file_exists ($ file )) {
179
+ } elseif (!@ unlink ( $ file ) && file_exists ($ file )) {
176
180
$ error = error_get_last ();
177
181
throw new IOException (sprintf ('Failed to remove file "%s": %s. ' , $ file , $ error ['message ' ]));
178
182
}
0 commit comments