Skip to content

Commit

Permalink
reverted usage of recursiveDelete() back to use rmdir(). replaced ite…
Browse files Browse the repository at this point in the history
…rators with filelist where needed

Signed-off-by: CaCO3 <[email protected]>
  • Loading branch information
CaCO3 committed Nov 1, 2023
1 parent 6b2e9cc commit 65c2068
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
20 changes: 16 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, \SplFileInfo> */
$fileList = iterator_to_array($this->getRecursiveDirectoryIterator(), true);
foreach ($fileList as $path => $fileInfo) {
$currentDir = $this->baseDir . '/../';
$fileName = explode($currentDir, $path)[1];
$folderStructure = explode('/', $fileName, -1);
Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 16 additions & 4 deletions lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, \SplFileInfo> */
$fileList = iterator_to_array($this->getRecursiveDirectoryIterator(), true);
foreach ($fileList as $path => $fileInfo) {
$currentDir = $this->baseDir . '/../';
$fileName = explode($currentDir, $path)[1];
$folderStructure = explode('/', $fileName, -1);
Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 65c2068

Please sign in to comment.