Skip to content

Commit

Permalink
Improve "rimraf" replacement and use for all cleanup
Browse files Browse the repository at this point in the history
This should no longer crash out if the file/folder does not exist, exactly like how the "rm -rf" command functions.
  • Loading branch information
bennothommo committed Dec 29, 2023
1 parent d3b99de commit 3da8246
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions public/install/api/src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,10 @@ public function postCleanUp()

// Remove install files
$this->log->notice('Removing installation files');
@unlink($this->workDir('winter.zip'));
@unlink($this->rootDir('install.html'));
@unlink($this->rootDir('install.zip'));
@unlink($this->rootDir('.ignore-ssl'));
$this->rimraf($this->workDir('winter.zip'));
$this->rimraf($this->rootDir('install.html'));
$this->rimraf($this->rootDir('install.zip'));
$this->rimraf($this->rootDir('.ignore-ssl'));

// Remove install folders
$this->log->notice('Removing temporary installation folders');
Expand All @@ -687,13 +687,13 @@ public function postCleanUp()
$this->log->notice('Removing core development files');
$this->rimraf($this->workDir('.github'));
$this->rimraf($this->workDir('.gitpod'));
@unlink($this->workDir('.gitattributes'));
@unlink($this->workDir('.gitpod.yml'));
@unlink($this->workDir('.jshintrc'));
@unlink($this->workDir('.babelrc'));
@unlink($this->workDir('CHANGELOG.md'));
@unlink($this->workDir('phpunit.xml'));
@unlink($this->workDir('phpcs.xml'));
$this->rimraf($this->workDir('.gitattributes'));
$this->rimraf($this->workDir('.gitpod.yml'));
$this->rimraf($this->workDir('.jshintrc'));
$this->rimraf($this->workDir('.babelrc'));
$this->rimraf($this->workDir('CHANGELOG.md'));
$this->rimraf($this->workDir('phpunit.xml'));
$this->rimraf($this->workDir('phpcs.xml'));

// Move files from subdirectory into install folder
$this->log->notice('Moving files from temporary work directory to final installation path', [
Expand Down Expand Up @@ -1117,13 +1117,22 @@ protected function generateKey(): string

/**
* PHP-based "rm -rf" command.
*
*
* Recursively removes a directory and all files and subdirectories within.
*
*
* @return void
*/
protected function rimraf(string $path)
{
if (!file_exists($path)) {
return;
}

if (is_file($path)) {
@unlink($path);
return;
}

$dir = new DirectoryIterator($path);

foreach ($dir as $item) {
Expand Down

0 comments on commit 3da8246

Please sign in to comment.