1
0
Fork 0

Return null for install path for metapackages instead of an empty path which then resolves to the root package's path (#11455)

Fixes #11389
pull/11474/head
Jordi Boggiano 2023-05-14 13:46:46 +02:00 committed by GitHub
parent a79eef2949
commit 3a48e39375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 63 additions and 23 deletions

View File

@ -157,9 +157,8 @@ source for the exact signature):
invoked with the update argument. invoked with the update argument.
* **uninstall()**, here you can determine the actions that need to be executed * **uninstall()**, here you can determine the actions that need to be executed
when the package needs to be removed. when the package needs to be removed.
* **getInstallPath()**, this method should return the location where the * **getInstallPath()**, this method should return the absolute path where the
package is to be installed, _relative from the location of composer.json._ package is to be installed. The path _must not end with a slash._
The path _must not end with a slash._
Example: Example:

View File

@ -485,10 +485,14 @@ EOF;
continue; continue;
} }
$this->validatePackage($package); $this->validatePackage($package);
$installPath = $installationManager->getInstallPath($package);
if ($installPath === null) {
continue;
}
$packageMap[] = [ $packageMap[] = [
$package, $package,
$installationManager->getInstallPath($package), $installPath,
]; ];
} }

View File

@ -332,7 +332,12 @@ EOT
} }
if ($input->getOption('path')) { if ($input->getOption('path')) {
$io->write($package->getName(), false); $io->write($package->getName(), false);
$io->write(' ' . strtok(realpath($composer->getInstallationManager()->getInstallPath($package)), "\r\n")); $path = $composer->getInstallationManager()->getInstallPath($package);
if (is_string($path)) {
$io->write(' ' . strtok(realpath($path), "\r\n"));
} else {
$io->write(' null');
}
return $exitCode; return $exitCode;
} }
@ -509,7 +514,12 @@ EOT
$packageViewData['description'] = $package->getDescription(); $packageViewData['description'] = $package->getDescription();
} }
if ($writePath) { if ($writePath) {
$packageViewData['path'] = strtok(realpath($composer->getInstallationManager()->getInstallPath($package)), "\r\n"); $path = $composer->getInstallationManager()->getInstallPath($package);
if (is_string($path)) {
$packageViewData['path'] = strtok(realpath($path), "\r\n");
} else {
$packageViewData['path'] = null;
}
} }
$packageIsAbandoned = false; $packageIsAbandoned = false;
@ -635,7 +645,7 @@ EOT
} }
/** /**
* @param array<array{name: string, direct-dependency?: bool, version?: string, latest?: string, latest-status?: string, description?: string|null, path?: string, source?: string|null, homepage?: string|null, warning?: string, abandoned?: bool|string}> $packages * @param array<array{name: string, direct-dependency?: bool, version?: string, latest?: string, latest-status?: string, description?: string|null, path?: string|null, source?: string|null, homepage?: string|null, warning?: string, abandoned?: bool|string}> $packages
*/ */
private function printPackages(IOInterface $io, array $packages, string $indent, bool $writeVersion, bool $writeLatest, bool $writeDescription, int $width, int $versionLength, int $nameLength, int $latestLength): void private function printPackages(IOInterface $io, array $packages, string $indent, bool $writeVersion, bool $writeLatest, bool $writeDescription, int $width, int $versionLength, int $nameLength, int $latestLength): void
{ {
@ -669,8 +679,8 @@ EOT
} }
$io->write(' ' . $description, false); $io->write(' ' . $description, false);
} }
if (isset($package['path'])) { if (array_key_exists('path', $package)) {
$io->write(' ' . $package['path'], false); $io->write(' '.(is_string($package['path']) ? $package['path'] : 'null'), false);
} }
$io->write(''); $io->write('');
if (isset($package['warning'])) { if (isset($package['warning'])) {
@ -802,7 +812,12 @@ EOT
$io->write('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference())); $io->write('<info>source</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getSourceType(), $package->getSourceUrl(), $package->getSourceReference()));
$io->write('<info>dist</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference())); $io->write('<info>dist</info> : ' . sprintf('[%s] <comment>%s</comment> %s', $package->getDistType(), $package->getDistUrl(), $package->getDistReference()));
if ($installedRepo->hasPackage($package)) { if ($installedRepo->hasPackage($package)) {
$io->write('<info>path</info> : ' . sprintf('%s', realpath($this->requireComposer()->getInstallationManager()->getInstallPath($package)))); $path = $this->requireComposer()->getInstallationManager()->getInstallPath($package);
if (is_string($path)) {
$io->write('<info>path</info> : ' . realpath($path));
} else {
$io->write('<info>path</info> : null');
}
} }
$io->write('<info>names</info> : ' . implode(', ', $package->getNames())); $io->write('<info>names</info> : ' . implode(', ', $package->getNames()));
@ -958,9 +973,14 @@ EOT
} }
if ($installedRepo->hasPackage($package)) { if ($installedRepo->hasPackage($package)) {
$path = realpath($this->requireComposer()->getInstallationManager()->getInstallPath($package)); $path = $this->requireComposer()->getInstallationManager()->getInstallPath($package);
if ($path !== false) { if (is_string($path)) {
$json['path'] = $path; $path = realpath($path);
if ($path !== false) {
$json['path'] = $path;
}
} else {
$json['path'] = null;
} }
} }

View File

@ -99,6 +99,9 @@ EOT
foreach ($installedRepo->getCanonicalPackages() as $package) { foreach ($installedRepo->getCanonicalPackages() as $package) {
$downloader = $dm->getDownloaderForPackage($package); $downloader = $dm->getDownloaderForPackage($package);
$targetDir = $im->getInstallPath($package); $targetDir = $im->getInstallPath($package);
if ($targetDir === null) {
continue;
}
if ($downloader instanceof ChangeReportInterface) { if ($downloader instanceof ChangeReportInterface) {
if (is_link($targetDir)) { if (is_link($targetDir)) {

View File

@ -112,6 +112,9 @@ EOT
$localRepo = $composer->getRepositoryManager()->getLocalRepository(); $localRepo = $composer->getRepositoryManager()->getLocalRepository();
foreach ($localRepo->getPackages() as $package) { foreach ($localRepo->getPackages() as $package) {
$path = $composer->getInstallationManager()->getInstallPath($package); $path = $composer->getInstallationManager()->getInstallPath($package);
if (null === $path) {
continue;
}
$file = $path . '/composer.json'; $file = $path . '/composer.json';
if (is_dir($path) && file_exists($file)) { if (is_dir($path) && file_exists($file)) {
[$errors, $publishErrors, $warnings] = $validator->validate($file, $checkAll, $checkVersion); [$errors, $publishErrors, $warnings] = $validator->validate($file, $checkAll, $checkVersion);

View File

@ -549,9 +549,9 @@ class InstallationManager
/** /**
* Returns the installation path of a package * Returns the installation path of a package
* *
* @return string path * @return string|null absolute path to install to, which does not end with a slash, or null if the package does not have anything installed on disk
*/ */
public function getInstallPath(PackageInterface $package): string public function getInstallPath(PackageInterface $package): ?string
{ {
$installer = $this->getInstaller($package->getType()); $installer = $this->getInstaller($package->getType());

View File

@ -112,7 +112,7 @@ interface InstallerInterface
/** /**
* Returns the absolute installation path of a package. * Returns the absolute installation path of a package.
* *
* @return string absolute path to install to, which MUST not end with a slash * @return string|null absolute path to install to, which MUST not end with a slash, or null if the package does not have anything installed on disk
*/ */
public function getInstallPath(PackageInterface $package); public function getInstallPath(PackageInterface $package);
} }

View File

@ -227,6 +227,8 @@ class LibraryInstaller implements InstallerInterface, BinaryPresenceInterface
/** /**
* @inheritDoc * @inheritDoc
*
* @return string
*/ */
public function getInstallPath(PackageInterface $package) public function getInstallPath(PackageInterface $package)
{ {

View File

@ -124,9 +124,11 @@ class MetapackageInstaller implements InstallerInterface
/** /**
* @inheritDoc * @inheritDoc
*
* @return null
*/ */
public function getInstallPath(PackageInterface $package) public function getInstallPath(PackageInterface $package)
{ {
return ''; return null;
} }
} }

View File

@ -115,7 +115,7 @@ class ProjectInstaller implements InstallerInterface
/** /**
* Returns the installation path of a package * Returns the installation path of a package
* *
* @return string path * @return string configured install path
*/ */
public function getInstallPath(PackageInterface $package): string public function getInstallPath(PackageInterface $package): string
{ {

View File

@ -473,7 +473,11 @@ class Locker
return null; return null;
} }
$path = realpath($this->installationManager->getInstallPath($package)); $path = $this->installationManager->getInstallPath($package);
if ($path === null) {
return null;
}
$path = realpath($path);
$sourceType = $package->getSourceType(); $sourceType = $package->getSourceType();
$datetime = null; $datetime = null;

View File

@ -236,8 +236,11 @@ class PluginManager
continue; continue;
} }
$downloadPath = $this->getInstallPath($autoloadPackage, $globalRepo && $globalRepo->hasPackage($autoloadPackage)); $installPath = $this->getInstallPath($autoloadPackage, $globalRepo && $globalRepo->hasPackage($autoloadPackage));
$autoloads[] = [$autoloadPackage, $downloadPath]; if ($installPath === null) {
continue;
}
$autoloads[] = [$autoloadPackage, $installPath];
} }
$map = $generator->parseAutoloads($autoloads, $rootPackage); $map = $generator->parseAutoloads($autoloads, $rootPackage);
@ -524,9 +527,9 @@ class PluginManager
* *
* @param bool $global Whether this is a global package * @param bool $global Whether this is a global package
* *
* @return string Install path * @return string|null Install path
*/ */
private function getInstallPath(PackageInterface $package, bool $global = false): string private function getInstallPath(PackageInterface $package, bool $global = false): ?string
{ {
if (!$global) { if (!$global) {
return $this->composer->getInstallationManager()->getInstallPath($package); return $this->composer->getInstallationManager()->getInstallPath($package);