Skip to content

Commit

Permalink
feat(config): Allow Scoop to ignore running processes during reset/un…
Browse files Browse the repository at this point in the history
…install/update (ScoopInstaller#4713)

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
  • Loading branch information
CrendKing and niheaven authored Feb 11, 2022
1 parent 3345a5e commit 14854c3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Features

- **config:** Allow Scoop to ignore running processes during reset/uninstall/update ([#4713](https://github.com/ScoopInstaller/Scoop/issues/4713))
- **scoop-download:** Add `scoop download` command ([#4621](https://github.com/ScoopInstaller/Scoop/issues/4621))
- **scoop-(install|virustotal):** Allow skipping update check ([#4634](https://github.com/ScoopInstaller/Scoop/issues/4634))
- **scoop-bucket:** List more detailed information for buckets ([#4704](https://github.com/ScoopInstaller/Scoop/pull/4704))
Expand Down
14 changes: 14 additions & 0 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1211,3 +1211,17 @@ function persist_permission($manifest, $global) {
$acl | Set-Acl -Path $path
}
}

# test if there are running processes
function test_running_process($app, $global) {
$processdir = appdir $app $global | Convert-Path
$running_processes = Get-Process | Where-Object { $_.Path -like "$processdir\*" }

if ($running_processes -and !(get_config 'ignore_running_processes')) {
error "Application `"$app`" is still running. Close all instances and try again."
return $true
} else {
warn "Application `"$app`" is still running. Scoop is configured to ignore this condition."
return $false
}
}
5 changes: 5 additions & 0 deletions libexec/scoop-config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
# API key used for uploading/scanning files using virustotal.
# See: 'https://support.virustotal.com/hc/en-us/articles/115002088769-Please-give-me-an-API-key'
#
# ignore_running_processes: $true|$false
# When set to $false (default), Scoop would stop its procedure immediately if it detects
# any target app process is running. Procedure here refers to reset/uninstall/update.
# When set to $true, Scoop only displays a warning message and continues procedure.
#
# ARIA2 configuration
# -------------------
#
Expand Down
4 changes: 1 addition & 3 deletions libexec/scoop-reset.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ $apps | ForEach-Object {
$persist_dir = persistdir $app $global

#region Workaround for #2952
$processdir = $dir | Select-Object -ExpandProperty Path
if (Get-Process | Where-Object { $_.Path -like "$processdir\*" }) {
error "Application is still running. Close all instances and try again."
if (test_running_process $app $global) {
continue
}
#endregion Workaround for #2952
Expand Down
4 changes: 1 addition & 3 deletions libexec/scoop-uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ if (!$apps) { exit 0 }
$persist_dir = persistdir $app $global

#region Workaround for #2952
$processdir = $appDir | Resolve-Path | Select-Object -ExpandProperty Path
if (Get-Process | Where-Object { $_.Path -like "$processdir\*" }) {
error 'Application is still running. Close all instances and try again.'
if (test_running_process $app $global) {
continue
}
#endregion Workaround for #2952
Expand Down
4 changes: 1 addition & 3 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ function update($app, $global, $quiet = $false, $independent, $suggested, $use_c
$persist_dir = persistdir $app $global

#region Workaround for #2952
$processdir = appdir $app $global | Resolve-Path | Select-Object -ExpandProperty Path
if (Get-Process | Where-Object { $_.Path -like "$processdir\*" }) {
error "Application is still running. Close all instances and try again."
if (test_running_process $app $global) {
return
}
#endregion Workaround for #2952
Expand Down

0 comments on commit 14854c3

Please sign in to comment.