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'); }