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 ced36b2 commit 82da28a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 25 additions & 4 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,7 @@ function link_current($versiondir) {
Remove-Item $currentdir -Recurse -Force -ErrorAction Stop
}

New-Item -Path $currentdir -ItemType Junction -Value $versiondir | Out-Null
attrib $currentdir +R /L
New-DirectoryJunction $currentdir $versiondir
return $currentdir
}

Expand Down Expand Up @@ -1207,8 +1206,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
attrib $source +R /L
New-DirectoryJunction $source $target
} else {
# target is a file, create hard link
New-Item -Path $source -ItemType HardLink -Value $target | Out-Null
Expand Down Expand Up @@ -1270,3 +1268,26 @@ function test_running_process($app, $global) {
return $false
}
}

# test if this script is being executed inside a docker container
function Test-IsInsideContainer {
$foundService = Get-Service -Name cexecsvc -ErrorAction SilentlyContinue
if ( $foundService -eq $null ) {
$false
}
else {
$true
}
}

# wrapper function to create junction links
# Required to handle docker/for-win#12240
function New-DirectoryJunction($source, $target) {
if (Test-IsInsideContainer) {
& "$env:COMSPEC" /c "mklink /j `"$source`" `"$target`"" | out-null
} else {
New-Item -Path $source -ItemType Junction -Value $target | Out-Null
}
attrib $source +R /L
}

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 82da28a

Please sign in to comment.