Audit locked packages if update is called with --no-install, fixes #10894
parent
611b215896
commit
e3c46cb2b2
|
@ -388,19 +388,25 @@ class Installer
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->audit) {
|
if ($this->audit) {
|
||||||
$packages = $localRepo->getCanonicalPackages();
|
if ($this->update && !$this->install) {
|
||||||
|
$packages = $lockedRepository->getCanonicalPackages();
|
||||||
|
$target = 'locked';
|
||||||
|
} else {
|
||||||
|
$packages = $localRepo->getCanonicalPackages();
|
||||||
|
$target = 'installed';
|
||||||
|
}
|
||||||
if (count($packages) > 0) {
|
if (count($packages) > 0) {
|
||||||
try {
|
try {
|
||||||
$auditor = new Auditor(Factory::createHttpDownloader($this->io, $this->config));
|
$auditor = new Auditor(Factory::createHttpDownloader($this->io, $this->config));
|
||||||
$auditor->audit($this->io, $packages, $this->auditFormat);
|
$auditor->audit($this->io, $packages, $this->auditFormat);
|
||||||
} catch (TransportException $e) {
|
} catch (TransportException $e) {
|
||||||
$this->io->error('Failed to audit installed packages.');
|
$this->io->error('Failed to audit '.$target.' packages.');
|
||||||
if ($this->io->isVerbose()) {
|
if ($this->io->isVerbose()) {
|
||||||
$this->io->error($e->getMessage());
|
$this->io->error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->io->writeError('No packages - skipping audit.');
|
$this->io->writeError('No '.$target.' packages - skipping audit.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Composer.
|
||||||
|
*
|
||||||
|
* (c) Nils Adermann <naderman@naderman.de>
|
||||||
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Composer\Repository;
|
||||||
|
|
||||||
|
use Composer\Package\AliasPackage;
|
||||||
|
use Composer\Package\PackageInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides getCanonicalPackages() to various repository implementations
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
trait CanonicalPackagesTrait
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get unique packages (at most one package of each name), with aliases resolved and removed.
|
||||||
|
*
|
||||||
|
* @return PackageInterface[]
|
||||||
|
*/
|
||||||
|
public function getCanonicalPackages()
|
||||||
|
{
|
||||||
|
$packages = $this->getPackages();
|
||||||
|
|
||||||
|
// get at most one package of each name, preferring non-aliased ones
|
||||||
|
$packagesByName = array();
|
||||||
|
foreach ($packages as $package) {
|
||||||
|
if (!isset($packagesByName[$package->getName()]) || $packagesByName[$package->getName()] instanceof AliasPackage) {
|
||||||
|
$packagesByName[$package->getName()] = $package;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$canonicalPackages = array();
|
||||||
|
|
||||||
|
// unfold aliased packages
|
||||||
|
foreach ($packagesByName as $package) {
|
||||||
|
while ($package instanceof AliasPackage) {
|
||||||
|
$package = $package->getAliasOf();
|
||||||
|
}
|
||||||
|
|
||||||
|
$canonicalPackages[] = $package;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $canonicalPackages;
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,8 @@ namespace Composer\Repository;
|
||||||
*/
|
*/
|
||||||
class LockArrayRepository extends ArrayRepository
|
class LockArrayRepository extends ArrayRepository
|
||||||
{
|
{
|
||||||
|
use CanonicalPackagesTrait;
|
||||||
|
|
||||||
public function getRepoName(): string
|
public function getRepoName(): string
|
||||||
{
|
{
|
||||||
return 'lock repo';
|
return 'lock repo';
|
||||||
|
|
|
@ -22,6 +22,8 @@ use Composer\Installer\InstallationManager;
|
||||||
*/
|
*/
|
||||||
class WritableArrayRepository extends ArrayRepository implements WritableRepositoryInterface
|
class WritableArrayRepository extends ArrayRepository implements WritableRepositoryInterface
|
||||||
{
|
{
|
||||||
|
use CanonicalPackagesTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
|
@ -69,33 +71,4 @@ class WritableArrayRepository extends ArrayRepository implements WritableReposit
|
||||||
{
|
{
|
||||||
$this->devMode = null;
|
$this->devMode = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function getCanonicalPackages()
|
|
||||||
{
|
|
||||||
$packages = $this->getPackages();
|
|
||||||
|
|
||||||
// get at most one package of each name, preferring non-aliased ones
|
|
||||||
$packagesByName = array();
|
|
||||||
foreach ($packages as $package) {
|
|
||||||
if (!isset($packagesByName[$package->getName()]) || $packagesByName[$package->getName()] instanceof AliasPackage) {
|
|
||||||
$packagesByName[$package->getName()] = $package;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$canonicalPackages = array();
|
|
||||||
|
|
||||||
// unfold aliased packages
|
|
||||||
foreach ($packagesByName as $package) {
|
|
||||||
while ($package instanceof AliasPackage) {
|
|
||||||
$package = $package->getAliasOf();
|
|
||||||
}
|
|
||||||
|
|
||||||
$canonicalPackages[] = $package;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $canonicalPackages;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue