Skip to content

Commit

Permalink
Fix symlinks inside containers
Browse files Browse the repository at this point in the history
Co-Authored-By: Rashil Gandhi <46838874+rashil2000@users.noreply.github.com>
  • Loading branch information
kingster and rashil2000 committed Mar 22, 2022
1 parent ced36b2 commit 889cba6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,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 @@ -1207,7 +1207,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 @@ -1270,3 +1270,15 @@ function test_running_process($app, $global) {
return $false
}
}

# wrapper function to create junction links
# Required to handle docker/for-win#12240
function New-DirectoryJunction($source, $target) {
# test if this script is being executed inside a docker container
if (Get-Service -Name cexecsvc -ErrorAction SilentlyContinue) {
cmd.exe /d /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 889cba6

Please sign in to comment.