Skip to content

Commit 74fec35

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: (23 commits) [Filesystem] Better error handling in remove() [DependencyInjection] Add coverage for invalid Expression in exportParameters [DependencyInjection] Add coverage for all invalid arguments in exportParameters anonymous services are always private [Console] Correct time formatting. [WebProfilerBundle] Fixed error from unset twig variable Force profiler toolbar svg display [DependencyInjection] Resolve aliases before removing abstract services + add tests Fix Dom Crawler select option with empty value Remove unnecessary option assignment fix tests (use non-deprecated options) remove unused variable mock the proper method [PropertyAccess] Fix regression [HttpFoundation] Improve phpdoc [Logging] Add support for firefox in ChromePhpHandler Windows 10 version check in just one line Detect CLI color support for Windows 10 build 10586 [Security] Fixed SwitchUserListener when exiting an impersonication with AnonymousToken [EventDispatcher] Try first if the event is Stopped ...
2 parents f82499a + dee3791 commit 74fec35

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Filesystem.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,27 @@ public function touch($files, $time = null, $atime = null)
155155
*/
156156
public function remove($files)
157157
{
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+
}
159163
$files = array_reverse($files);
160164
foreach ($files as $file) {
161-
if (@(unlink($file) || rmdir($file))) {
162-
continue;
163-
}
164165
if (is_link($file)) {
165166
// 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+
}
168171
} elseif (is_dir($file)) {
169-
$this->remove(new \FilesystemIterator($file));
172+
$this->remove(new \FilesystemIterator($file, \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS));
170173

171-
if (!@rmdir($file)) {
174+
if (!@rmdir($file) && file_exists($file)) {
172175
$error = error_get_last();
173176
throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, $error['message']));
174177
}
175-
} elseif (file_exists($file)) {
178+
} elseif (!@unlink($file) && file_exists($file)) {
176179
$error = error_get_last();
177180
throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
178181
}

0 commit comments

Comments
 (0)