Skip to content

Commit

Permalink
fix(install): Fix bugs in #5715 (#5824)
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven committed Mar 7, 2024
1 parent 7e3dc73 commit 54e0514
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -52,7 +52,7 @@

- **git:** Use Invoke-Git() with direct path to git.exe to prevent spawning shim subprocesses ([#5122](https://github.com/ScoopInstaller/Scoop/issues/5122), [#5375](https://github.com/ScoopInstaller/Scoop/issues/5375))
- **scoop-download:** Output more detailed manifest information ([#5277](https://github.com/ScoopInstaller/Scoop/issues/5277))
- **core:** Cleanup some old codes, e.g., msi section and config migration ([#5715](https://github.com/ScoopInstaller/Scoop/issues/5715))
- **core:** Cleanup some old codes, e.g., msi section and config migration ([#5715](https://github.com/ScoopInstaller/Scoop/issues/5715), [#5824](https://github.com/ScoopInstaller/Scoop/issues/5824))

### Builds

Expand Down
58 changes: 27 additions & 31 deletions lib/install.ps1
Expand Up @@ -712,27 +712,23 @@ function run_installer($fname, $manifest, $architecture, $dir, $global) {
Invoke-Command ([scriptblock]::Create($installer.script -join "`r`n"))
return
}
install_prog $fname $dir $installer $global
}

function install_prog($fname, $dir, $installer, $global) {
$prog = "$dir\$(coalesce $installer.file "$fname")"
if (!(is_in_dir $dir $prog)) {
abort "Error in manifest: Installer $prog is outside the app directory."
}
$arg = @(args $installer.args $dir $global)

if ($prog.endswith('.ps1')) {
& $prog @arg
} else {
$installed = Invoke-ExternalCommand $prog $arg -Activity 'Running installer...'
if (!$installed) {
abort "Installation aborted. You might need to run 'scoop uninstall $app' before trying again."
if ($installer) {
$prog = "$dir\$(coalesce $installer.file "$fname")"
if (!(is_in_dir $dir $prog)) {
abort "Error in manifest: Installer $prog is outside the app directory."
}

# Don't remove installer if "keep" flag is set to true
if (!($installer.keep -eq 'true')) {
Remove-Item $prog
$arg = @(args $installer.args $dir $global)
if ($prog.endswith('.ps1')) {
& $prog @arg
} else {
$installed = Invoke-ExternalCommand $prog $arg -Activity 'Running installer...'
if (!$installed) {
abort "Installation aborted. You might need to run 'scoop uninstall $app' before trying again."
}
# Don't remove installer if "keep" flag is set to true
if (!($installer.keep -eq 'true')) {
Remove-Item $prog
}
}
}
}
Expand All @@ -747,21 +743,21 @@ function run_uninstaller($manifest, $architecture, $dir) {
}

if ($uninstaller.file) {
$exe = "$dir\$($uninstaller.file)"
$prog = "$dir\$($uninstaller.file)"
$arg = args $uninstaller.args
if (!(is_in_dir $dir $exe)) {
warn "Error in manifest: Installer $exe is outside the app directory, skipping."
$exe = $null
} elseif (!(Test-Path $exe)) {
warn "Uninstaller $exe is missing, skipping."
$exe = $null
if (!(is_in_dir $dir $prog)) {
warn "Error in manifest: Installer $prog is outside the app directory, skipping."
$prog = $null
} elseif (!(Test-Path $prog)) {
warn "Uninstaller $prog is missing, skipping."
$prog = $null
}

if ($exe) {
if ($exe.endswith('.ps1')) {
& $exe @arg
if ($prog) {
if ($prog.endswith('.ps1')) {
& $prog @arg
} else {
$uninstalled = Invoke-ExternalCommand $exe $arg -Activity 'Running uninstaller...'
$uninstalled = Invoke-ExternalCommand $prog $arg -Activity 'Running uninstaller...'
if (!$uninstalled) {
abort 'Uninstallation aborted.'
}
Expand Down

0 comments on commit 54e0514

Please sign in to comment.