Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace all rmdir by a recursive variant #508

Closed
wants to merge 13 commits into from
30 changes: 25 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,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
*
Expand Down Expand Up @@ -844,10 +864,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 +973,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 +1027,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 +1072,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
31 changes: 26 additions & 5 deletions lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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');
}
Expand Down
Loading