Skip to content

Commit

Permalink
Add a more drastic method of ensuring composer version from env (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Jun 7, 2024
1 parent 5e639e8 commit d6c1e30
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,18 @@ public function run()
}
// Support an alternate composer version based on env var.
if (!empty($_ENV['ALTERNATE_COMPOSER_PATH'])) {
$allow_list = [
'/usr/local/bin/composer22',
];
if (!in_array($_ENV['ALTERNATE_COMPOSER_PATH'], $allow_list)) {
throw new \InvalidArgumentException('The alternate composer path is not allowed');
}
$this->log('Trying to use composer from ' . $_ENV['ALTERNATE_COMPOSER_PATH']);
copy($_ENV['ALTERNATE_COMPOSER_PATH'], __DIR__ . '/../../../../vendor/bin/composer');
if (file_exists('/usr/local/bin/composer')) {
rename('/usr/local/bin/composer', '/usr/local/bin/composer.bak');
}
copy($_ENV['ALTERNATE_COMPOSER_PATH'], '/usr/local/bin/composer');
chmod('/usr/local/bin/composer', 0755);
}
// Try to get the php version as well.
$this->execCommand(['php', '--version']);
Expand Down Expand Up @@ -1768,6 +1778,9 @@ private function cleanUp()
$this->chdir('/tmp');
$this->log('Cleaning up after update check.');
$this->execCommand(['rm', '-rf', $this->tmpDir], false, 300);
if (file_exists('/usr/local/bin/composer.bak')) {
rename('/usr/local/bin/composer.bak', '/usr/local/bin/composer');
}
}

/**
Expand Down

0 comments on commit d6c1e30

Please sign in to comment.