From f47f7dabe3cf2c1d53316db2cbc674c08d0e68a0 Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Sun, 22 Oct 2023 23:50:46 +0200 Subject: [PATCH] replace all rmdir by a recursive variant --- index.php | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 69c1d161..3e84708f 100644 --- a/index.php +++ b/index.php @@ -61,6 +61,24 @@ public function accept(): bool { } +function rrmdir($src) { + $dir = opendir($src); + while(false !== ( $file = readdir($dir)) ) { + if (( $file != '.' ) && ( $file != '..' )) { + $full = $src . '/' . $file; + if ( is_dir($full) ) { + rrmdir($full); + } + else { + unlink($full); + } + } + } + closedir($dir); + rmdir($src); +} + + class Updater { private string $baseDir; private array $configValues = []; @@ -844,10 +862,10 @@ private function recursiveDelete(string $folder): void { unlink($file); } foreach ($directories as $dir) { - rmdir($dir); + rrmdir($dir); } - $state = rmdir($folder); + $state = rrmdir($folder); if ($state === false) { throw new \Exception('Could not rmdir ' . $folder); } @@ -953,7 +971,7 @@ public function deleteOldFiles(): void { throw new \Exception('Could not unlink: '.$path); } } elseif ($fileInfo->isDir()) { - $state = rmdir($path); + $state = rrmdir($path); if ($state === false) { throw new \Exception('Could not rmdir: '.$path); } @@ -1007,7 +1025,7 @@ private function moveWithExclusions(string $dataLocation, array $excludedElement } } if ($fileInfo->isDir()) { - $state = rmdir($path); + $state = rrmdir($path); if ($state === false) { throw new \Exception('Could not rmdir ' . $path); } @@ -1052,7 +1070,7 @@ public function finalize(): void { $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/nextcloud/'; $this->silentLog('[info] storage location: ' . $storageLocation); $this->moveWithExclusions($storageLocation, []); - $state = rmdir($storageLocation); + $state = rrmdir($storageLocation); if ($state === false) { throw new \Exception('Could not rmdir $storagelocation'); }