1
0
Fork 0

Tweak virtualbox detection and improve it by detecting vbox additions, refs #9627

pull/9803/head
Jordi Boggiano 2021-04-01 09:48:07 +02:00
parent 836ca051d3
commit 53a974f9c9
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 36 additions and 12 deletions

View File

@ -998,6 +998,15 @@ cannot be guessed from VCS info and is not present in `composer.json`.
By setting this var you can make Composer install the dependencies into a
directory other than `vendor`.
### COMPOSER_RUNTIME_ENV
This lets you hint under which environment Composer is running, which can help Composer
work around some environment specific issues. The only value currently supported is
`virtualbox`, which then enables some short `sleep()` calls to wait for the filesystem
to have written files properly before we attempt reading them. You can set the
environment variable if you use Vagrant or VirtualBox and experience issues with files not
being found during installation even though they should be present.
### http_proxy or HTTP_PROXY
If you are using Composer from behind an HTTP proxy, you can use the standard

View File

@ -20,7 +20,7 @@ namespace Composer\Util;
class Platform
{
/** @var ?bool */
private static $isVagrantGuest = null;
private static $isVirtualBoxGuest = null;
/**
* Parses tildes and environment variables in paths.
@ -123,34 +123,49 @@ class Platform
public static function workaroundFilesystemIssues()
{
if (self::isVagrantGuest()) {
if (self::isVirtualBoxGuest()) {
usleep(200000);
}
}
/**
* Attempts detection of vagrant guest VMs
* Attempts detection of VirtualBox guest VMs
*
* This works based on the process' user being "vagrant", or the COMPOSER_RUNTIME_ENV env var being set to "vagrant"
* This works based on the process' user being "vagrant", the COMPOSER_RUNTIME_ENV env var being set to "virtualbox", or lsmod showing the virtualbox guest additions are loaded
*
* @return bool
*/
private static function isVagrantGuest()
private static function isVirtualBoxGuest()
{
if (null === self::$isVagrantGuest) {
self::$isVagrantGuest = false;
if (!self::isWindows() && function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
if (null === self::$isVirtualBoxGuest) {
self::$isVirtualBoxGuest = false;
if (self::isWindows()) {
return self::$isVirtualBoxGuest;
}
if (function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
$processUser = posix_getpwuid(posix_geteuid());
if ($processUser && $processUser['name'] === 'vagrant') {
return self::$isVagrantGuest = true;
return self::$isVirtualBoxGuest = true;
}
}
if (getenv('COMPOSER_RUNTIME_ENV') === 'vagrant') {
return self::$isVagrantGuest = true;
if (getenv('COMPOSER_RUNTIME_ENV') === 'virtualbox') {
return self::$isVirtualBoxGuest = true;
}
if (defined('PHP_OS_FAMILY') && PHP_OS_FAMILY === 'Linux') {
$process = new ProcessExecutor();
try {
if (0 === $process->execute('lsmod | grep vboxguest', $ignoredOutput)) {
return self::$isVirtualBoxGuest = true;
}
} catch (\Exception $e) {
// noop
}
}
}
return self::$isVagrantGuest;
return self::$isVirtualBoxGuest;
}
}