Dart エラー「ERROR: Cannot delete output file : アクセスが拒否されました。」でupgradeできない

  • 作成日 2022.10.19
  • 更新日 2022.10.21
  • Dart
Dart エラー「ERROR: Cannot delete output file : アクセスが拒否されました。」でupgradeできない

Dartで、エラー「ERROR: Cannot delete output file : アクセスが拒否されました。」でupgradeできない場合の対処法を記述してます。

環境

  • OS windows11 home

エラー内容

「upgrade」実行時に発生。
※管理者としてコマンドプロンプト上で実行

> choco upgrade dart-sdk

エラーメッセージ

ERROR: Cannot delete output file : アクセスが拒否されました。 : C:\tools\dart-sdk\bin\dart.exe
ERROR: 7-Zip encountered a fatal error while extracting the files. This is most likely an issue with the 'dart-sdk' package and not with Chocolatey itself. Please follow up with the package maintainer(s) directly.
The upgrade of dart-sdk was NOT successful.
Error while running 'C:\ProgramData\chocolatey\lib\dart-sdk\chocolateyInstall.ps1'.
 See log for details.

Chocolatey upgraded 0/1 packages. 1 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Failures
 - dart-sdk (exited 2) - Error while running 'C:\ProgramData\chocolatey\lib\dart-sdk\chocolateyInstall.ps1'.
 See log for details.

原因

「VSCODE」上で使用していたため

解決方法

「VSCODE」を閉じて再度実行することで解決しました。

> choco upgrade dart-sdk

Chocolatey v1.1.0
2 validations performed. 1 success(es), 1 warning(s), and 0 error(s).

Validation Warnings:
 - A pending system reboot request has been detected, however, this is
   being ignored due to the current Chocolatey configuration.  If you
   want to halt when this occurs, then either set the global feature
   using:
     choco feature enable -name=exitOnRebootDetected
   or pass the option --exit-when-reboot-detected.

Upgrading the following packages:
dart-sdk
By upgrading, you accept licenses for the packages.
dart-sdk is not installed. Installing...
Progress: Downloading dart-sdk 2.18.2... 100%
Progress: Downloading dart-sdk 2.18.2... 100%

dart-sdk v2.18.2 [Approved]
dart-sdk package files upgrade completed. Performing other installation steps.
The package dart-sdk wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): y

File appears to be downloaded already. Verifying with package checksum to determine if it needs to be redownloaded.
Hashes match.
Hashes match.
Extracting C:\Users\testuser\AppData\Local\Temp\dart-sdk\2.18.2\dartsdk-windows-x64-release.zip to C:\tools...
C:\tools
 The upgrade of dart-sdk was successful.
  Software installed to 'C:\tools'

Chocolatey upgraded 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Did you know the proceeds of Pro (and some proceeds from other
 licensed editions) go into bettering the community infrastructure?
 Your support ensures an active community, keeps Chocolatey tip-top,
 plus it nets you some awesome features!
 https://chocolatey.org/compare