Skip to content

Commit 3da8246

Browse files
committed
Improve "rimraf" replacement and use for all cleanup
This should no longer crash out if the file/folder does not exist, exactly like how the "rm -rf" command functions.
1 parent d3b99de commit 3da8246

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

public/install/api/src/Api.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,10 @@ public function postCleanUp()
673673

674674
// Remove install files
675675
$this->log->notice('Removing installation files');
676-
@unlink($this->workDir('winter.zip'));
677-
@unlink($this->rootDir('install.html'));
678-
@unlink($this->rootDir('install.zip'));
679-
@unlink($this->rootDir('.ignore-ssl'));
676+
$this->rimraf($this->workDir('winter.zip'));
677+
$this->rimraf($this->rootDir('install.html'));
678+
$this->rimraf($this->rootDir('install.zip'));
679+
$this->rimraf($this->rootDir('.ignore-ssl'));
680680

681681
// Remove install folders
682682
$this->log->notice('Removing temporary installation folders');
@@ -687,13 +687,13 @@ public function postCleanUp()
687687
$this->log->notice('Removing core development files');
688688
$this->rimraf($this->workDir('.github'));
689689
$this->rimraf($this->workDir('.gitpod'));
690-
@unlink($this->workDir('.gitattributes'));
691-
@unlink($this->workDir('.gitpod.yml'));
692-
@unlink($this->workDir('.jshintrc'));
693-
@unlink($this->workDir('.babelrc'));
694-
@unlink($this->workDir('CHANGELOG.md'));
695-
@unlink($this->workDir('phpunit.xml'));
696-
@unlink($this->workDir('phpcs.xml'));
690+
$this->rimraf($this->workDir('.gitattributes'));
691+
$this->rimraf($this->workDir('.gitpod.yml'));
692+
$this->rimraf($this->workDir('.jshintrc'));
693+
$this->rimraf($this->workDir('.babelrc'));
694+
$this->rimraf($this->workDir('CHANGELOG.md'));
695+
$this->rimraf($this->workDir('phpunit.xml'));
696+
$this->rimraf($this->workDir('phpcs.xml'));
697697

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

11181118
/**
11191119
* PHP-based "rm -rf" command.
1120-
*
1120+
*
11211121
* Recursively removes a directory and all files and subdirectories within.
1122-
*
1122+
*
11231123
* @return void
11241124
*/
11251125
protected function rimraf(string $path)
11261126
{
1127+
if (!file_exists($path)) {
1128+
return;
1129+
}
1130+
1131+
if (is_file($path)) {
1132+
@unlink($path);
1133+
return;
1134+
}
1135+
11271136
$dir = new DirectoryIterator($path);
11281137

11291138
foreach ($dir as $item) {

0 commit comments

Comments
 (0)