Skip to content

Commit

Permalink
Improve clearDirectory method
Browse files Browse the repository at this point in the history
  • Loading branch information
M0rgan01 committed Feb 5, 2025
1 parent 64d96e5 commit 54e28d2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions classes/UpgradeTools/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,26 @@ public function isReleaseValid(string $path): bool
return true;
}

public function clearDirectory(string $folderToClear): bool
public function clearDirectory(string $folderToClear, bool $deleteFolder = false): bool
{
$hasDeletedItems = false;

if ($this->filesystem->exists($folderToClear)) {
foreach (scandir($folderToClear) as $item) {
if ($item !== '.' && $item !== '..' && $item !== 'index.php') {
$path = $folderToClear . DIRECTORY_SEPARATOR . $item;
$this->filesystem->remove($path);

return true;
$hasDeletedItems = true;
}
}

if ($deleteFolder) {
$this->filesystem->remove($folderToClear);
$hasDeletedItems = true;
}
}

return false;
return $hasDeletedItems;
}
}

0 comments on commit 54e28d2

Please sign in to comment.