Skip to content

Commit

Permalink
Add handling for LibraryInstaller returning PromiseInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jun 5, 2020
1 parent 8669edf commit 5006d0c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Composer/Installers/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Composer\Package\PackageInterface;
use Composer\Repository\InstalledRepositoryInterface;
use Composer\Util\Filesystem;
use React\Promise\PromiseInterface;

class Installer extends LibraryInstaller
{
Expand Down Expand Up @@ -160,9 +161,21 @@ public function getInstallPath(PackageInterface $package)

public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
{
parent::uninstall($repo, $package);
$installPath = $this->getPackageBasePath($package);
$this->io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
$io = $this->io;
$outputStatus = function () use ($io, $installPath) {
$io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
};

$promise = parent::uninstall($repo, $package);

// Composer v2 might return a promise here
if ($promise instanceof PromiseInterface) {
return $promise->then($outputStatus);
}

// If not, execute the code right away as parent::uninstall executed synchronously (composer v1, or v2 without async)
$outputStatus();
}

/**
Expand Down

16 comments on commit 5006d0c

@tiefenb
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I get the same issue - but this worked for long time. Did something change here?

image

@Seldaek
Copy link
Member Author

@Seldaek Seldaek commented on 5006d0c Oct 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is due to a custom installer plugin interacting badly with Composer 2.

Please check which plugins you have installed. If you run for example composer diagnose -vvv somewhere on top of the output it should show Loading plugin Some\Class\Name.

One of these is most likely the cause for the problems, so you have to report the error on that plugin's repository. Or also you can try to composer update plugin/package --no-plugins to make sure you have the latest version of the plugin installed, perhaps it has been fixed already.

This commit here is just an example of how other plugins can also fix it. It's not related to the problem you are experiencing.

@pedroaccamara
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi I also have the same problem, and I have very little experience with Openshift.
Although I have a different output from his, I can see in his case, it says "Failed to extract blue-tomato/elascticsearch-feeder".
From what I understand of your reply, the plugin "blue-tomato/elascticsearch-feeder" is the plugin that's causing the trouble correct? i.e. not the composer?
My question is, if I can't even install the plugin, how can I possibly update it? In my case at least, the log has just installed the plugin "wyrihaximus/twig-view" and shortly after "Failed to extract wyrihaximus/twig-view" followed by "cannot find or open /opt/app-root/src/vendor/composer/tmp-8b325c55671adf08e12a9a92d86c0f32" this composer path.
So is there nothing wrong with the composer then, and just the plugin? and how can I update it if the installation in the first place went wrong?

@denisbondar
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The yiisoft/yii2-composer update helped me.

I had the same error when trying to run composer install. I didn't need to update all the dependencies. Updating yiisoft/yii2-composer to 2.0.10 solved this problem.

composer require yiisoft/yii2-composer

@cnbase
Copy link

@cnbase cnbase commented on 5006d0c Jan 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The yiisoft/yii2-composer update helped me.

I had the same error when trying to run composer install. I didn't need to update all the dependencies. Updating yiisoft/yii2-composer to 2.0.10 solved this problem.

composer require yiisoft/yii2-composer

use version 1.xxx is ok.

@Yuenlx
Copy link

@Yuenlx Yuenlx commented on 5006d0c Mar 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The yiisoft/yii2-composer update helped me.
I had the same error when trying to run composer install. I didn't need to update all the dependencies. Updating yiisoft/yii2-composer to 2.0.10 solved this problem.

composer require yiisoft/yii2-composer

use version 1.xxx is ok.

composer self-update --1

@NigelCunningham
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

composer self-update --1

If you do that, you're going back to composer 1, so that's not helpful, sorry. Composer 2 is way faster and uses less memory. It's the way of the future and rightly so. We need to deal with issues, not hide from them.

@crispy-computing-machine

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both issues appear to be with composer deps?

Loading plugin PackageVersions\Installer (from composer/package-versions-deprecated)
Loading plugin UpdateHelper\ComposerPlugin (from kylekatarnls/update-helper)

@ola-mymed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to know if @Seldaek 's suggestions worked for others because it didn't work for me. composer diagnose -vvv didn't reveal any problematic plugins. composer global update used to work fine when I was on composer v1, so I'm sure my issue, which is the same @tiefenb's, must be related to composer v2 somehow. Ideas anyone, please?

@Seldaek
Copy link
Member Author

@Seldaek Seldaek commented on 5006d0c Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ola-mymed report a new issue with details on how to reproduce the issue and the name of the plugins perhaps so we can have a look.

@dharake
Copy link

@dharake dharake commented on 5006d0c Sep 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

composer config -g repo.packagist composer https://packagist.org

That fixed it for me, hope that helps

@damiankosiorowski
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Composer v2.
After a night of combining, it worked:

  1. Remove composer.lock
  2. composer clearcache
  3. composer install

@Nicholaskrs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you have try all option and none work try delete whole vendor file if you have it somehow it's work for me

@umpirsky
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrading composer to version 2.2.5 from 2.1.6 fixed it for me.

@jxmallett
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using the docker image. I didn't realise mine was way out of date. I had to manually remove the image and pull it again.

docker image rm composer
docker pull composer

@danog
Copy link

@danog danog commented on 5006d0c Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One possible cause for this issue (which made me loose about half an hour) is two or more composer processes running in the same folder.

In my case this happened because I had configured parallel CI steps in woodpecker, thinking that they ran in separate containers with no shared folders, while they actually run in separate containers, but sharing the repo folder in a volume.

Using a lock to avoid race conditions during composer update fixed the issue for me.

Please sign in to comment.