@@ -140,24 +140,27 @@ public function touch($files, $time = null, $atime = null)
140
140
*/
141
141
public function remove ($ files )
142
142
{
143
- $ files = iterator_to_array ($ this ->toIterator ($ files ));
143
+ if ($ files instanceof \Traversable) {
144
+ $ files = iterator_to_array ($ files , false );
145
+ } elseif (!is_array ($ files )) {
146
+ $ files = array ($ files );
147
+ }
144
148
$ files = array_reverse ($ files );
145
149
foreach ($ files as $ file ) {
146
- if (@(unlink ($ file ) || rmdir ($ file ))) {
147
- continue ;
148
- }
149
150
if (is_link ($ file )) {
150
151
// See https://bugs.php.net/52176
151
- $ error = error_get_last ();
152
- throw new IOException (sprintf ('Failed to remove symlink "%s": %s. ' , $ file , $ error ['message ' ]));
152
+ if (!@(unlink ($ file ) || '\\' !== DIRECTORY_SEPARATOR || rmdir ($ file )) && file_exists ($ file )) {
153
+ $ error = error_get_last ();
154
+ throw new IOException (sprintf ('Failed to remove symlink "%s": %s. ' , $ file , $ error ['message ' ]));
155
+ }
153
156
} elseif (is_dir ($ file )) {
154
- $ this ->remove (new \FilesystemIterator ($ file ));
157
+ $ this ->remove (new \FilesystemIterator ($ file, \FilesystemIterator:: CURRENT_AS_PATHNAME | \FilesystemIterator:: SKIP_DOTS ));
155
158
156
- if (!@rmdir ($ file )) {
159
+ if (!@rmdir ($ file ) && file_exists ( $ file ) ) {
157
160
$ error = error_get_last ();
158
161
throw new IOException (sprintf ('Failed to remove directory "%s": %s. ' , $ file , $ error ['message ' ]));
159
162
}
160
- } elseif (file_exists ($ file )) {
163
+ } elseif (!@ unlink ( $ file ) && file_exists ($ file )) {
161
164
$ error = error_get_last ();
162
165
throw new IOException (sprintf ('Failed to remove file "%s": %s. ' , $ file , $ error ['message ' ]));
163
166
}
0 commit comments