diff --git a/index.php b/index.php index 1d52a376..62a58896 100644 --- a/index.php +++ b/index.php @@ -937,7 +937,10 @@ public function deleteOldFiles(): void { * @var string $path * @var \SplFileInfo $fileInfo */ - foreach ($this->getRecursiveDirectoryIterator() as $path => $fileInfo) { + // Build file list first, so the removals won't mess with it + /** @var array */ + $fileList = iterator_to_array($this->getRecursiveDirectoryIterator(), true); + foreach ($fileList as $path => $fileInfo) { $currentDir = $this->baseDir . '/../'; $fileName = explode($currentDir, $path)[1]; $folderStructure = explode('/', $fileName, -1); @@ -957,7 +960,10 @@ public function deleteOldFiles(): void { throw new \Exception('Could not unlink: ' . $path); } } elseif ($fileInfo->isDir()) { - $this->recursiveDelete($path); + $state = rmdir($path); + if ($state === false) { + throw new \Exception('Could not rmdir: '.$path); + } } } @@ -1011,7 +1017,10 @@ private function moveWithExclusions(string $dataLocation, array $excludedElement } } if ($fileInfo->isDir()) { - $this->recursiveDelete($path); + $state = rmdir($path); + if ($state === false) { + throw new \Exception('Could not rmdir ' . $path); + } } } } @@ -1053,7 +1062,10 @@ public function finalize(): void { $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/nextcloud/'; $this->silentLog('[info] storage location: ' . $storageLocation); $this->moveWithExclusions($storageLocation, []); - $this->recursiveDelete($storageLocation); + $state = rmdir($storageLocation); + if ($state === false) { + throw new \Exception('Could not rmdir ' . $storagelocation); + } $state = unlink($this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/.step'); if ($state === false) { diff --git a/lib/Updater.php b/lib/Updater.php index 2ceee61b..cc8d3d93 100644 --- a/lib/Updater.php +++ b/lib/Updater.php @@ -899,7 +899,10 @@ public function deleteOldFiles(): void { * @var string $path * @var \SplFileInfo $fileInfo */ - foreach ($this->getRecursiveDirectoryIterator() as $path => $fileInfo) { + // Build file list first, so the removals won't mess with it + /** @var array */ + $fileList = iterator_to_array($this->getRecursiveDirectoryIterator(), true); + foreach ($fileList as $path => $fileInfo) { $currentDir = $this->baseDir . '/../'; $fileName = explode($currentDir, $path)[1]; $folderStructure = explode('/', $fileName, -1); @@ -919,7 +922,10 @@ public function deleteOldFiles(): void { throw new \Exception('Could not unlink: ' . $path); } } elseif ($fileInfo->isDir()) { - $this->recursiveDelete($path); + $state = rmdir($path); + if ($state === false) { + throw new \Exception('Could not rmdir: '.$path); + } } } @@ -973,7 +979,10 @@ private function moveWithExclusions(string $dataLocation, array $excludedElement } } if ($fileInfo->isDir()) { - $this->recursiveDelete($path); + $state = rmdir($path); + if ($state === false) { + throw new \Exception('Could not rmdir ' . $path); + } } } } @@ -1015,7 +1024,10 @@ public function finalize(): void { $storageLocation = $this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/downloads/nextcloud/'; $this->silentLog('[info] storage location: ' . $storageLocation); $this->moveWithExclusions($storageLocation, []); - $this->recursiveDelete($storageLocation); + $state = rmdir($storageLocation); + if ($state === false) { + throw new \Exception('Could not rmdir ' . $storagelocation); + } $state = unlink($this->getUpdateDirectoryLocation() . '/updater-'.$this->getConfigOptionMandatoryString('instanceid') . '/.step'); if ($state === false) {