1
0
Fork 0

Attempt working around Vagrant filesystem issues, added COMPOSER_RUNTIME_ENV env var (set to vagrant), fixes #9627

pull/9771/head
Jordi Boggiano 2021-03-10 10:45:40 +01:00
parent 17747181d0
commit 414586ba05
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
3 changed files with 41 additions and 0 deletions

View File

@ -26,6 +26,7 @@ use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
use Composer\EventDispatcher\EventDispatcher;
use Composer\Util\Loop;
use Composer\Util\Platform;
use React\Promise\PromiseInterface;
/**
@ -440,6 +441,8 @@ class InstallationManager
$this->waitOnPromises($promises);
}
Platform::workaroundFilesystemIssues();
foreach ($postExecCallbacks as $cb) {
$cb();
}

View File

@ -18,6 +18,7 @@ use Composer\Repository\InstalledRepositoryInterface;
use Composer\Package\PackageInterface;
use Composer\Util\Filesystem;
use Composer\Installer\InstallationManager;
use Composer\Util\Platform;
use React\Promise\PromiseInterface;
/**
@ -97,6 +98,7 @@ class PluginInstaller extends LibraryInstaller
return $promise->then(function () use ($self, $pluginManager, $initial, $target, $repo) {
try {
Platform::workaroundFilesystemIssues();
$pluginManager->deactivatePackage($initial, true);
$pluginManager->registerPackage($target, true);
} catch (\Exception $e) {

View File

@ -19,6 +19,9 @@ namespace Composer\Util;
*/
class Platform
{
/** @var ?bool */
private static $isVagrantGuest = null;
/**
* Parses tildes and environment variables in paths.
*
@ -117,4 +120,37 @@ class Platform
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
}
public static function workaroundFilesystemIssues()
{
if (self::isVagrantGuest()) {
usleep(200000);
}
}
/**
* Attempts detection of vagrant guest VMs
*
* This works based on the process' user being "vagrant", or the COMPOSER_RUNTIME_ENV env var being set to "vagrant"
*
* @return bool
*/
private static function isVagrantGuest()
{
if (null === self::$isVagrantGuest) {
self::$isVagrantGuest = false;
if (!self::isWindows() && function_exists('posix_getpwuid') && function_exists('posix_geteuid')) {
$processUser = posix_getpwuid(posix_geteuid());
if ($processUser && $processUser['name'] === 'vagrant') {
return self::$isVagrantGuest = true;
}
}
if (getenv('COMPOSER_RUNTIME_ENV') === 'vagrant') {
return self::$isVagrantGuest = true;
}
}
return self::$isVagrantGuest;
}
}