Skip to content

Commit

Permalink
replace all rmdir by a recursive variant
Browse files Browse the repository at this point in the history
  • Loading branch information
caco3 committed Oct 22, 2023
1 parent 55eca48 commit f47f7da
Showing 1 changed file with 23 additions and 5 deletions.
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

0 comments on commit f47f7da

Please sign in to comment.