Skip to content

Commit

Permalink
Enabled shimming of external applications (#2072)
Browse files Browse the repository at this point in the history
* Enabled shimming of external applications

* Improved correctness of target binding at shimming point.

* Fixed '| % { return ... }' issue.
  • Loading branch information
excitoon authored and r15ch13 committed May 4, 2018
1 parent 6236750 commit 3e14f37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
9 changes: 9 additions & 0 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ powershell -noprofile -ex unrestricted `"& '$resolved_path' $arg %args%;exit `$l
}
}

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 @@ -682,14 +682,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

0 comments on commit 3e14f37

Please sign in to comment.