Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
replace all rmdir by a recursive variant
Signed-off-by: CaCO3 <caco@ruinelli.ch>
  • Loading branch information
caco3 authored and CaCO3 committed Oct 26, 2023
commit f53fba3a957b7b5a5e8339fba21737970baf97db
28 changes: 23 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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');
}
Expand Down