googleapis / google-api-php-client

A PHP client library for accessing Google APIs
Apache License 2.0
9.22k stars 3.52k forks source link

Cleanup cannot remove dir on WSL #2490

Closed daniel-sc closed 8 months ago

daniel-sc commented 11 months ago

When using the "cleanup" script on WSL it errors with:

  [Symfony\Component\Filesystem\Exception\IOException]
  Failed to remove directory "/mnt/c/dev/my-project/vendor/google/apiclient-services/src/Aiplatform": rmdir(/mnt/c/dev/my-project/vendor/google/apiclient-services/src/Aiplatform): Directory not empty.

Environment details

Steps to reproduce

  1. Run composer install on/in WSL2

Code example

package.json:

{
  "config": {
    "process-timeout": 2400
  },
  "autoload": {
    "classmap": [
      "asdf/api/",
      "asdf/backup/",
      "asdf/storage/",
      "asdf/mail/",
      "asdf/mongo-failover/",
      "asdf/notification/",
      "asdf/aop/"
    ]
  },
  "autoload-dev": {
    "classmap": [
      "tests/phpunit/"
    ]
  },
  "require": {
    "php": "~8.1",
    "mongodb/mongodb": "~1.16.0",
    "datadog/php-datadogstatsd": "1.3.0",
    "flowjs/flow-php-server": "1.2.0",
    "phpmailer/phpmailer": "^6.8.0",
    "psr/log": "^1.1.4",
    "mikecao/flight": "2.0.1",
    "podio-community/podio-php": "~7.0.0",
    "stripe/stripe-php": "^7.0.2",
    "guzzlehttp/guzzle": "^7.7.0",
    "twig/twig": "~v3.3.0",
    "google/apiclient": "~v2.15.0",
    "google/apiclient-services": "v0.312.1",
    "ext-openssl": "*",
    "ext-mongodb": "1.16.2",
    "ext-json": "*",
    "ext-pcntl": "*"
  },
  "require-dev": {
    "phpunit/phpunit": "^9.6.10",
    "rector/rector": "^0.17.5"
  },
  "name": "my-package",
  "description": "",
  "scripts": {
    "pre-autoload-dump": "Google\\Task\\Composer::cleanup"
  },
  "extra": {
    "google/apiclient-services": [
      "Compute",
      "Storage",
      "Logging"
    ]
  }
}

Output:

root@daniel-t14s:/mnt/c/dev/my-project# rm -rf vendor/composer/
root@daniel-t14s:/mnt/c/dev/my-project# rm -rf vendor/google/
root@daniel-t14s:/mnt/c/dev/my-project# composer install
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]?
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
Package operations: 62 installs, 0 updates, 0 removals
  - Downloading datadog/php-datadogstatsd (1.3.0)
  - Downloading flowjs/flow-php-server (v1.2.0)
  - Downloading paragonie/random_compat (v9.99.100)
  - Downloading paragonie/constant_time_encoding (v2.6.3)
  - Downloading phpseclib/phpseclib (3.0.21)
  - Downloading psr/log (1.1.4)
  - Downloading monolog/monolog (2.9.1)
  - Downloading ralouphie/getallheaders (3.0.3)
  - Downloading psr/http-message (2.0)
  - Downloading psr/http-factory (1.0.2)
  - Downloading guzzlehttp/psr7 (2.6.0)
  - Downloading psr/http-client (1.0.2)
  - Downloading guzzlehttp/promises (2.0.1)
  - Downloading guzzlehttp/guzzle (7.7.0)
  - Downloading google/apiclient-services (v0.312.1)
  - Downloading mikecao/flight (v2.0.1)
  - Downloading symfony/polyfill-php81 (v1.27.0)
  - Downloading symfony/polyfill-php80 (v1.27.0)
  - Downloading symfony/polyfill-php73 (v1.27.0)
  - Downloading jean85/pretty-package-versions (2.0.5)
  - Downloading mongodb/mongodb (1.16.0)
  - Downloading symfony/polyfill-ctype (v1.27.0)
  - Downloading phpmailer/phpmailer (v6.8.0)
  - Downloading sebastian/global-state (5.0.6)
  - Downloading nikic/php-parser (v4.17.1)
  - Downloading phpunit/php-code-coverage (9.2.27)
  - Downloading symfony/polyfill-mbstring (v1.27.0)
  - Downloading phpunit/phpunit (9.6.11)
  - Downloading podio-community/podio-php (v7.0.0)
  - Downloading phpstan/phpstan (1.10.30)
  - Downloading rector/rector (0.17.13)
  - Downloading stripe/stripe-php (v7.128.0)
  - Downloading twig/twig (v3.3.10)
  - Installing datadog/php-datadogstatsd (1.3.0): Extracting archive
  - Installing flowjs/flow-php-server (v1.2.0): Extracting archive
  - Installing paragonie/random_compat (v9.99.100): Extracting archive
  - Installing paragonie/constant_time_encoding (v2.6.3): Extracting archive
  - Installing phpseclib/phpseclib (3.0.21): Extracting archive
  - Installing psr/log (1.1.4): Extracting archive
  - Installing monolog/monolog (2.9.1): Extracting archive
  - Installing ralouphie/getallheaders (3.0.3): Extracting archive
  - Installing psr/http-message (2.0): Extracting archive
  - Installing psr/http-factory (1.0.2): Extracting archive
  - Installing guzzlehttp/psr7 (2.6.0): Extracting archive
  - Installing symfony/deprecation-contracts (v3.3.0): Extracting archive
  - Installing psr/http-client (1.0.2): Extracting archive
  - Installing guzzlehttp/promises (2.0.1): Extracting archive
  - Installing guzzlehttp/guzzle (7.7.0): Extracting archive
  - Installing psr/cache (3.0.0): Extracting archive
  - Installing firebase/php-jwt (v6.8.1): Extracting archive
  - Installing google/auth (v1.29.1): Extracting archive
  - Installing google/apiclient-services (v0.312.1): Extracting archive
  - Installing google/apiclient (v2.15.0): Extracting archive
  - Installing mikecao/flight (v2.0.1): Extracting archive
  - Installing symfony/polyfill-php81 (v1.27.0): Extracting archive
  - Installing symfony/polyfill-php80 (v1.27.0): Extracting archive
  - Installing symfony/polyfill-php73 (v1.27.0): Extracting archive
  - Installing jean85/pretty-package-versions (2.0.5): Extracting archive
  - Installing mongodb/mongodb (1.16.0): Extracting archive
  - Installing symfony/polyfill-ctype (v1.27.0): Extracting archive
  - Installing phpmailer/phpmailer (v6.8.0): Extracting archive
  - Installing sebastian/version (3.0.2): Extracting archive
  - Installing sebastian/type (3.2.1): Extracting archive
  - Installing sebastian/resource-operations (3.0.3): Extracting archive
  - Installing sebastian/recursion-context (4.0.5): Extracting archive
  - Installing sebastian/object-reflector (2.0.4): Extracting archive
  - Installing sebastian/object-enumerator (4.0.4): Extracting archive
  - Installing sebastian/global-state (5.0.6): Extracting archive
  - Installing sebastian/exporter (4.0.5): Extracting archive
  - Installing sebastian/environment (5.1.5): Extracting archive
  - Installing sebastian/diff (4.0.5): Extracting archive
  - Installing sebastian/comparator (4.0.8): Extracting archive
  - Installing sebastian/code-unit (1.0.8): Extracting archive
  - Installing sebastian/cli-parser (1.0.1): Extracting archive
  - Installing phpunit/php-timer (5.0.3): Extracting archive
  - Installing phpunit/php-text-template (2.0.4): Extracting archive
  - Installing phpunit/php-invoker (3.1.1): Extracting archive
  - Installing phpunit/php-file-iterator (3.0.6): Extracting archive
  - Installing theseer/tokenizer (1.2.1): Extracting archive
  - Installing nikic/php-parser (v4.17.1): Extracting archive
  - Installing sebastian/lines-of-code (1.0.3): Extracting archive
  - Installing sebastian/complexity (2.0.2): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
  - Installing phpunit/php-code-coverage (9.2.27): Extracting archive
  - Installing phar-io/version (3.2.1): Extracting archive
  - Installing phar-io/manifest (2.0.3): Extracting archive
  - Installing myclabs/deep-copy (1.11.1): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.27.0): Extracting archive
  - Installing doctrine/instantiator (2.0.0): Extracting archive
  - Installing phpunit/phpunit (9.6.11): Extracting archive
  - Installing podio-community/podio-php (v7.0.0): Extracting archive
  - Installing phpstan/phpstan (1.10.30): Extracting archive
  - Installing rector/rector (0.17.13): Extracting archive
  - Installing stripe/stripe-php (v7.128.0): Extracting archive
  - Installing twig/twig (v3.3.10): Extracting archive
 51/62 [=======================>----]  82%    Skipped installation of bin phpstan for package phpstan/phpstan: name conflicts with an existing file
    Skipped installation of bin phpstan.phar for package phpstan/phpstan: name conflicts with an existing file
 58/62 [==========================>-]  93%    Skipped installation of bin bin/php-parse for package nikic/php-parser: name conflicts with an existing file
 59/62 [==========================>-]  95%    Skipped installation of bin phpunit for package phpunit/phpunit: name conflicts with an existing file
 60/62 [===========================>]  96%    Skipped installation of bin bin/rector for package rector/rector: name conflicts with an existing file
 61/62 [===========================>]  98%
Generating autoload files
> Google\Task\Composer::cleanup
Removing 270 google services
Script Google\Task\Composer::cleanup handling the pre-autoload-dump event terminated with an exception

  [Symfony\Component\Filesystem\Exception\IOException]
  Failed to remove directory "/mnt/c/dev/my-project/vendor/google/apiclient-services/src/Aiplatform": rmd
  ir(/mnt/c/dev/my-project/vendor/google/apiclient-services/src/Aiplatform): Directory not empty.

install [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--dry-run] [--dev] [--no-suggest] [--no-dev] [--no-autoloader] [--no-progress] [--no-install] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--] [<packages>]...
vishwarajanand commented 8 months ago

This seems like an issue in your setup. Consider following tips:

  1. Avoid running composer install in sudo mode
  2. Clean your repo, remove composer.lock as well as vendor folder and re-attempt.

Hope this helps.

kcmcg commented 5 months ago

If anyone else ends up here with a composer install issue on wsl2. I determined I was having this issue while doing a composer install from Ubuntu on a Windows folder location (/mnt/c/*). I resolved it by creating a folder inside Ubuntu (/~/test_composer/), copying composer.json into that and running a fresh composer install. Then I copied the vendor folder and composer.lock back into the Windows folder.

ryo-ymmk commented 2 months ago

The handling of multi-threaded processing in Symfony is probably not very good. As a solution, repeatedly running the composer run-script pre-autoload-dump allows file deletion to progress little by little. https://github.com/symfony/symfony/issues/27578