windows 通过自我更新更新Composer时,为什么会出现错误/文件系统异常?

gudnpqoy  于 2022-12-05  发布在  Windows
关注(0)|答案(1)|浏览(596)

我刚刚在电脑上做了一个 composer 级别的例行检查,得到了一些意想不到的消息:

composer -V
PHP Deprecated:  Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Helper/HelperSet.php on line 112

Deprecated: Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Helper/HelperSet.php on line 112
Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of 
type string is deprecated in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:48
Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of 
type string is deprecated in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:48
Composer version 2.0.7 2020-11-13 17:31:06

我决定最简单的做法是更新Composer,因为这个版本已经有2年了,所以我运行了命令来更新,但是得到了同样的反对消息和一个实际的错误:

composer self-update
PHP Deprecated:  Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Helper/HelperSet.php on line 112

Deprecated: Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Helper/HelperSet.php on line 112
Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of 
type string is deprecated in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:48
Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of 
type string is deprecated in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:48
Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of 
type string is deprecated in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:48
Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of 
type string is deprecated in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:48
Upgrading to version 2.4.4 (stable channel).
   

  [Composer\Downloader\FilesystemException]
  Filesystem exception:                                                 
  Composer update failed: "C:\ProgramData\ComposerSetup\bin\composer.   
  phar" could not be written.                                           
  rename(C:\ProgramData\ComposerSetup\bin/composer-temp.phar,C:\Progr   
  amData\ComposerSetup\bin\composer.phar): Access is denied (code: 5)   
                                                                        

self-update [-r|--rollback] [--clean-backups] [--no-progress] [--update-keys] [--stable] [--preview] [--snapshot] [--1] [--2] [--set-channel-only] [--] [<version>]

重命名中涉及的两个文件都存在于C:\ProgramData\ComposerSetup\bin中,即composer.phar和composer-temp.phar,因此我认为错误是合理的:composer-temp.phar新名称已在使用中。
我该怎么做?将composer.phar重命名为composer.phar.old,然后再次尝试自我更新?还是会导致其他问题?

**composer diagnose**的输出:

composer diagnose
PHP Deprecated:  Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Helper/HelperSet.php on line 112

Deprecated: Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/symfony/console/Helper/HelperSet.php on line 112
Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of 
type string is deprecated in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:48
Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: Return type of Composer\Repository\ArrayRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/Repository/ArrayRepository.php:277
Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of 
type string is deprecated in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:48
Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of 
type string is deprecated in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:48
Deprecation Notice: strlen(): Passing null to parameter #1 ($string) of 
type string is deprecated in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/vendor/justinrainbow/json-schema/src/JsonSchema/Constraints/Constraint.php:48
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: You are not running the latest stable version, run `composer self-update` to update (2.0.7 => 2.4.4)
Composer version: 2.0.7
PHP version: 8.1.5
PHP binary path: C:\xampp\php\php.exe
OpenSSL version: OpenSSL 1.1.1n  15 Mar 2022
cURL version: 7.77.0 libz 1.2.12 ssl OpenSSL/1.1.1n
zip extension: OK
cwdobuhd

cwdobuhd1#

我该怎么做?将composer.phar重命名为composer.phar.old,然后再次尝试自我更新?还是会导致其他问题?
您可以尝试这样做,然后可能会发现composer命令不再运行(因为要执行的phar文件不在预期的位置),然后您可能会复制临时文件(显示在错误消息中),然后它可能已经工作了。
要点应该是:你不需要请求许可SO这样做,只要你记得你做了什么,并可以恢复以前的情况下,它没有计算,它是你的系统,你有控制(至少在一定程度上,因为它是Windows,但这是一个不同的东西).
在您的composer self-update期间(从弃用通知中减去噪声1),Composer遇到了一个没有您的干预就无法解决的情况,因此会告诉您:

[Composer\Downloader\FilesystemException]
  Filesystem exception:                                                 
  Composer update failed: "C:\ProgramData\ComposerSetup\bin\composer.   
  phar" could not be written.                                           
  rename(C:\ProgramData\ComposerSetup\bin/composer-temp.phar,C:\Progr   
  amData\ComposerSetup\bin\composer.phar): Access is denied (code: 5)

在Windows操作系统(OS)上,如果Composer是使用管理权限安装的,或者是由比执行composer self-update命令的用户具有更高权限的用户安装的,则通常会出现这种情况。

**信息:**在Windows上,文件可能会被锁定,直到下次重新启动系统。即使只使用更高级别的权限,也无法解除锁定,并且还需要重新启动(在适当的时间之前)。如果您关心此级别的详细信息,请查阅操作系统管理手册,了解为系统用户设置程序文件、应用程序及其数据所需的步骤。

使用所需权限执行composer self-update命令(错误消息建议至少写入C:\ProgramData\ComposerSetup\bin\composer.phar)或使用在系统上设置composer的原始方式建议的更新过程(例如setup.exeinstall.ini、MSI包、某些包管理器(如果正在使用)等)。
由于您在问题中没有首先提供您是如何安装Composer的,或者Composer是如何安装在该系统上的,因此无法更具体地写出在您的特定情况下是如何安装的。
就像你一样,我也会先用composer self-update,然后当得到这个错误时,也许 * 假设 * 在设置composer时正在使用composer windows安装程序,然后使用该安装程序来更新(如果它提供)或重新安装。但是,如果没有检查这种设置是否真正在使用中摆在首位,否则我会做适当的更新 * 原始安装程序 *。
Composer通常是一个漂亮的应用程序,因此重新安装通常应该这样做,Composer Windows安装程序处理了很多Windows特定的配置/设置事情,所以它增加了更多的帮助。但首先检查使用的是哪个安装程序,而不是你在同一个系统上 * 无意中 * 结束了两个不同的版本。
例如,可以检查安装程序是否可以在“程序”(Windows系统配置GUI中的一个)下卸载composer。它的好处是,如果安装程序提供了这样一个选项,不仅卸载,而且更新都有一个按钮可以点击。

**警告:**因此,完全重新安装系统可能是目前为止没有提到的最后一个选项,因为它会使原始配置无效,您可以从一个干净的石板“重新启动”。在这里只是作为一个警告提到它,以防读者可能会交叉这个想法,它是最昂贵的选项,应该避免,除非 * 所有 * 其他选项都不计算。

1.注册 * 过时通知中的噪音 *:您的php-cli ini配置中有display_errors,这些不是错误,只是信息或调试通知。在您的情况下,这意味着您已经将PHP更新到最新版本,只是工具与composer不完全一致。这可能会分散注意力,但只要只有弃用通知和警告,composer应该仍然可以正常工作。因此,这些消息看起来并不像是composer最初无法在您的系统上执行self-update事务的原因。

相关问题