Skip to content

Commit f304a0a

Browse files
Improve error handling in removeDirectory function
1 parent 004c9de commit f304a0a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cleanup.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,19 @@
2727

2828
function removeDirectory(string $dir): bool
2929
{
30-
if (! is_dir($dir)) {
30+
if (!is_dir($dir)) {
3131
return false;
3232
}
3333

3434
$files = array_diff(scandir($dir), ['.', '..']);
3535

3636
foreach ($files as $file) {
37-
$path = $dir.DIRECTORY_SEPARATOR.$file;
37+
$path = realpath($dir . DIRECTORY_SEPARATOR . $file);
38+
39+
// Als realpath faalt (bv. bestand is al weg), sla over
40+
if ($path === false) {
41+
continue;
42+
}
3843

3944
if (is_dir($path)) {
4045
removeDirectory($path);
@@ -45,3 +50,4 @@ function removeDirectory(string $dir): bool
4550

4651
return rmdir($dir);
4752
}
53+

0 commit comments

Comments
 (0)