Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "could not delete" with Composer on Vagrant

I have a Vagrant running Linux and I'm trying to install Symfony.

After the command composer create-project symfony/framework-standard-edition ./ "2.5.*" I have the error :

[RuntimeException]
  Could not delete ./.git/objects/pack/tmp_idx_llwUKb:

If I try to composer update another project, I always have this kind of error Could not delete

Any ideas?

Edit: For a simple sudo composer update -vvv on another project:

  - Installing sonata-project/admin-bundle (dev-master 8a022aa)
Failed to download sonata-project/admin-bundle from source: Could not delete /vagrant/crm_neo/vendor/sonata-project/admin-bundle/.git/objects/pack/tmp_idx_hchQhc:
Now trying to download from dist
  - Installing sonata-project/admin-bundle (dev-master 8a022aa)

Failed: [RuntimeException] Could not delete /vagrant/crm_neo/vendor/sonata-project/admin-bundle/.git/objects/pack/tmp_idx_hchQhc:



  [RuntimeException]
  Could not delete /vagrant/crm_neo/vendor/sonata-project/admin-bundle/.git/o
  bjects/pack/tmp_idx_hchQhc:



Exception trace:
 () at phar:///usr/local/bin/composer/src/Composer/Util/Filesystem.php:193
 Composer\Util\Filesystem->unlink() at phar:///usr/local/bin/composer/src/Composer/Util/Filesystem.php:151
 Composer\Util\Filesystem->removeDirectoryPhp() at phar:///usr/local/bin/composer/src/Composer/Util/Filesystem.php:129
 Composer\Util\Filesystem->removeDirectory() at phar:///usr/local/bin/composer/src/Composer/Util/Filesystem.php:35
 Composer\Util\Filesystem->remove() at phar:///usr/local/bin/composer/src/Composer/Util/Filesystem.php:80
 Composer\Util\Filesystem->emptyDirectory() at phar:///usr/local/bin/composer/src/Composer/Downloader/FileDownloader.php:108
 Composer\Downloader\FileDownloader->doDownload() at phar:///usr/local/bin/composer/src/Composer/Downloader/FileDownloader.php:89
 Composer\Downloader\FileDownloader->download() at phar:///usr/local/bin/composer/src/Composer/Downloader/ArchiveDownloader.php:35
 Composer\Downloader\ArchiveDownloader->download() at phar:///usr/local/bin/composer/src/Composer/Downloader/DownloadManager.php:201
 Composer\Downloader\DownloadManager->download() at phar:///usr/local/bin/composer/src/Composer/Installer/LibraryInstaller.php:156
 Composer\Installer\LibraryInstaller->installCode() at phar:///usr/local/bin/composer/src/Composer/Installer/LibraryInstaller.php:87
 Composer\Installer\LibraryInstaller->install() at phar:///usr/local/bin/composer/src/Composer/Installer/InstallationManager.php:152
 Composer\Installer\InstallationManager->install() at phar:///usr/local/bin/composer/src/Composer/Installer/InstallationManager.php:139
 Composer\Installer\InstallationManager->execute() at phar:///usr/local/bin/composer/src/Composer/Installer.php:548
 Composer\Installer->doInstall() at phar:///usr/local/bin/composer/src/Composer/Installer.php:217
 Composer\Installer->run() at phar:///usr/local/bin/composer/src/Composer/Command/UpdateCommand.php:128
 Composer\Command\UpdateCommand->execute() at phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:252
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:889
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:193
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:135
 Composer\Console\Application->doRun() at phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:124
 Symfony\Component\Console\Application->run() at phar:///usr/local/bin/composer/src/Composer/Console/Application.php:84
 Composer\Console\Application->run() at phar:///usr/local/bin/composer/bin/composer:43
 require() at /usr/local/bin/composer:15
like image 380
Clément Andraud Avatar asked Oct 06 '14 12:10

Clément Andraud


4 Answers

It happened once to me and it turns out that I was hitting composer's timeout.

You could take the following measures to gain some speed:

  1. Increase composer process-timeout (default 300) (not really needed if the following settings will help you gain speed, but can't hurt)
  2. Set dist as preferred install type.
  3. Enable https protocol for github, which is faster.

~/.composer/config.json

{
    "config": {
        "process-timeout":      600,
        "preferred-install":    "dist",
        "github-protocols":     ["https"]
    }
}

If you still have problems after that, you can also clear composer's cache:

rm -rf ~/.composer/cache
like image 95
Alexandru Guzinschi Avatar answered Nov 15 '22 10:11

Alexandru Guzinschi


I was trying to update project dependencies (using composer update) during a Laravel Framework upgrade exercise in my local Homestead environment (having run vagrant ssh to login as the default "vagrant" user) and none of the previous answers in this thread made any difference to the...

Could not delete /home/vagrant/projects/projectname/vendor/kylekatarnls/update-helper/src/UpdateHelper

...error message I repeatedly encountered.

The only thing that worked for me was to include a composer option as follows:

composer update --no-plugins

Plugins are used to alter or extend the functionality of Composer. The above command disables all installed plugins. Unfortunately, I'm not clear as to why this command worked for me, as I certainly haven't written any plugins myself. All I can conclude is that there was an erroneous Composer plugin installed that was causing this issue.

like image 21
w5m Avatar answered Nov 15 '22 08:11

w5m


TL;DR Switch to Docker. It is the industry standard.

I came across this issue and spent quite some time doing research. I've tried every possible option to fix it but none of them worked for me. For me, the bug occurred on GNU/Linux host with Vagrant and VirtualBox provider.

It turns out it's a VirtualBox bug related to the file system layer and race conditions when creating/deleting files. It occurs only for VirtualBox shared folders, not for regular ones. The sad part is that it seems like it's not going to be fixed any time soon.

Some guys reported that they were able to solve the problem using the following tricks:

  • Downgrading to VirtualBox version 6.0.4.
  • Using nfs or rsync instead of shared folders.
  • Patching composer to add some pauses after certain operations.
  • Disabling plugin usage with --no-plugins option.

But all of this seemed dirty to me. I personally was able to use a workaround suggested on GitHub which is to configure composer to install packages from sources. That's a simple and kind of clean trick which should not have significant negative side effects on your workflow. Try putting the following config into your ~/.config/composer/config.json. Or instead you can edit your composer.json accordingly depending on your needs. Keep in mind that composer.json will override your global config.

{
    "config": {
        "preferred-install": "source"
    }
}
like image 9
Kolyunya Avatar answered Nov 15 '22 09:11

Kolyunya


Just got the same issue.

I see the problem in accessing to some local files. In my case target directory was under "root" and I'm not the root user.

Solution

Change permissions/owner of your files/directory.

  1. Redefine owner:

    sudo chown myuser:myuser -R /path/to

  2. Maybe there is some lack of permissions for group which you are in.
    So, try to run:

    sudo chmod g+rwX -R /path/to

Or maybe you may run your command with "sudo" if it works for you (not recommended). :)

P.S. Never use 777. It's not secure.

UPD1

Another thing, you may found out useful to solve the root of the cause, to wrap up your composer binary to run it always behalf a certain user.

$ cat /usr/local/bin/composer
#!/bin/bash

# run composer behalf www-data user

set -o pipefail
set -o errexit
set -o nounset
#set -o xtrace

[[ "${DEBUG:-}" = "true" ]] && set -o xtrace || true

composer_debug=$([[ 'true' != "${COMPOSER_DEBUG:-}" ]] || echo '-vvv' )

sudo -u www-data -- /usr/bin/composer ${composer_debug:-} $@
like image 7
Kirby Avatar answered Nov 15 '22 09:11

Kirby