Skip to content

Commit

Permalink
Fix junction links
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster committed Mar 22, 2022
1 parent 7d5a47c commit 666e836
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ function link_current($versiondir) {
Remove-Item $currentdir -Recurse -Force -ErrorAction Stop
}

New-Item -Path $currentdir -ItemType Junction -Value $versiondir | Out-Null
New-DirectoryJunction($currentdir, $versiondir)
attrib $currentdir +R /L
return $currentdir
}
Expand Down Expand Up @@ -1197,7 +1197,7 @@ function persist_data($manifest, $original_dir, $persist_dir) {
# create link
if (is_directory $target) {
# target is a directory, create junction
New-Item -Path $source -ItemType Junction -Value $target | Out-Null
New-DirectoryJunction($source, $target)
attrib $source +R /L
} else {
# target is a file, create hard link
Expand Down Expand Up @@ -1260,3 +1260,28 @@ function test_running_process($app, $global) {
return $false
}
}

function Test-IsInsideContainer {
$foundService = Get-Service -Name cexecsvc -ErrorAction SilentlyContinue
if ( $foundService -eq $null ) {
$false
}
else {
$true
}
}

function New-DirectoryJunction($source, $target) {

if (Test-Path $target) {
warn "Target directory `$target` already exists."
return $false
}

if (Test-IsInsideContainer) {
& "$env:COMSPEC" /c "mklink /j `"$source`" `"$target`"" | out-null
} else {
New-Item -Path $source -ItemType Junction -Value $target | Out-Null
}

}
2 changes: 1 addition & 1 deletion lib/psmodules.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function install_psmodule($manifest, $dir, $global) {
Remove-Item -Path $linkfrom -Force -ErrorAction SilentlyContinue
}

New-Item -Path $linkfrom -ItemType Junction -Value $dir | Out-Null
New-DirectoryJunction($linkfrom, $dir)
}

function uninstall_psmodule($manifest, $dir, $global) {
Expand Down

0 comments on commit 666e836

Please sign in to comment.