From 2f7dda806588621e817fd85bc99ba331711bd05c Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Sun, 22 Oct 2023 23:50:46 +0200 Subject: [PATCH 1/3] replace all rmdir by a recursive variant Signed-off-by: CaCO3 --- 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'); } From 0c8c1be1fc90ab3f358c45e3b995ae0998312a09 Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Tue, 24 Oct 2023 23:19:00 +0200 Subject: [PATCH 2/3] add rmdir to lib/updater.php Signed-off-by: CaCO3 --- lib/Updater.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/Updater.php b/lib/Updater.php index 37d112d1..feeec142 100644 --- a/lib/Updater.php +++ b/lib/Updater.php @@ -297,6 +297,27 @@ private function getRecursiveDirectoryIterator(?string $folder = null): \Recursi ); } + /** + * Deletes a directory recursively + */ + private function rrmdir(string $src): void { + $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); + } + + /** * Checks for files that are unexpected. */ @@ -806,10 +827,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); } @@ -915,7 +936,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); } @@ -969,7 +990,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); } @@ -1014,7 +1035,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'); } From 7ad89452eebd360642156c4aac77d191e3286aa7 Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Thu, 26 Oct 2023 22:48:00 +0200 Subject: [PATCH 3/3] move function into class --- index.php | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/index.php b/index.php index 3e84708f..174d2dc6 100644 --- a/index.php +++ b/index.php @@ -61,24 +61,6 @@ 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 = []; @@ -149,6 +131,26 @@ public function __construct(string $baseDir) { $this->buildTime = $buildTime; } + /** + * Deletes a directory recursively + */ + private function rrmdir(string $src): void { + $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); + } + /** * Returns whether the web updater is disabled *