Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled shimming of external applications #2072

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,15 @@ powershell -noprofile -ex unrestricted `"& '$resolved_path' %args%;exit `$lastex
}
}

function search_in_path($target) {
$path = (env 'PATH' $false) + ";" + (env 'PATH' $true)
foreach($dir in $path.split(';')) {
if(test-path "$dir\$target" -pathType leaf) {
return "$dir\$target"
}
}
}

function ensure_in_path($dir, $global) {
$path = env 'PATH' $global
$dir = fullpath $dir
Expand Down
14 changes: 8 additions & 6 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,16 @@ function create_shims($manifest, $dir, $global, $arch) {
$target, $name, $arg = shim_def $_
write-output "Creating shim for '$name'."

# check valid bin
$bin = "$dir\$target"
if(!(is_in_dir $dir $bin)) {
abort "Error in manifest: bin '$target' is outside the app directory."
if(test-path "$dir\$target" -pathType leaf) {
$bin = "$dir\$target"
} elseif(test-path $target -pathType leaf) {
$bin = $target
} else {
$bin = search_in_path $target
}
if(!(test-path $bin)) { abort "Can't shim '$target': File doesn't exist."}
if(!$bin) { abort "Can't shim '$target': File doesn't exist."}

shim "$dir\$target" $global $name (substitute $arg @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir})
shim $bin $global $name (substitute $arg @{ '$dir' = $dir; '$original_dir' = $original_dir; '$persist_dir' = $persist_dir})
}
}

Expand Down