ScoopInstaller / Scoop

A command-line installer for Windows.
https://scoop.sh
Other
20.32k stars 1.37k forks source link

[Feature] scoop cleanup: add option for closing running apps to avoid "PermissionDenied" when apps are still running #5852

Open soredake opened 3 months ago

soredake commented 3 months ago

Feature Request

Is your feature request related to a problem? Please describe.

When you are cleaning old versions that are still running, you will receive "Remove-Item : Cannot remove item" error.

To reproduce this: 1) Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser 2) Invoke-RestMethod -Uri https://get.scoop.sh/ | Invoke-Expression 3) scoop install git 4) scoop bucket add extras 5) scoop install syncthingtray@1.4.13 6) run syncthing tray 7) scoop install syncthingtray@1.5.0 8) scoop cleanup -a -k 9) error:

Remove-Item : Cannot remove item C:\Users\ruruo\scoop\apps\syncthingtray\1.4.13\syncthingtray.exe: Access to the path
'syncthingtray.exe' is denied.
At C:\Users\ruruo\scoop\apps\scoop\current\libexec\scoop-cleanup.ps1:50 char:9
+         Remove-Item $dir -ErrorAction Stop -Recurse -Force
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (syncthingtray.exe:FileInfo) [Remove-Item], UnauthorizedAccessExceptio
   n
    + FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand

Related: https://github.com/ScoopInstaller/Scoop/issues/2035

Describe the solution you'd like

Add option to scoop cleanup for closing running apps to avoid "PermissionDenied" when apps are still running.

Describe alternatives you've considered

Not having such option.

soredake commented 1 month ago

Would be nice if this code can be adapted for cleanup command https://github.com/ScoopInstaller/Scoop/blob/d337bb1fa69a56637101254a1ac9e0ad13a12647/lib/install.ps1#L1147-L1165