Skip to content

Commit 82da28a

Browse files
committed
Fix junction links
1 parent ced36b2 commit 82da28a

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

lib/install.ps1

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,7 @@ function link_current($versiondir) {
956956
Remove-Item $currentdir -Recurse -Force -ErrorAction Stop
957957
}
958958

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

@@ -1207,8 +1206,7 @@ function persist_data($manifest, $original_dir, $persist_dir) {
12071206
# create link
12081207
if (is_directory $target) {
12091208
# target is a directory, create junction
1210-
New-Item -Path $source -ItemType Junction -Value $target | Out-Null
1211-
attrib $source +R /L
1209+
New-DirectoryJunction $source $target
12121210
} else {
12131211
# target is a file, create hard link
12141212
New-Item -Path $source -ItemType HardLink -Value $target | Out-Null
@@ -1270,3 +1268,26 @@ function test_running_process($app, $global) {
12701268
return $false
12711269
}
12721270
}
1271+
1272+
# test if this script is being executed inside a docker container
1273+
function Test-IsInsideContainer {
1274+
$foundService = Get-Service -Name cexecsvc -ErrorAction SilentlyContinue
1275+
if ( $foundService -eq $null ) {
1276+
$false
1277+
}
1278+
else {
1279+
$true
1280+
}
1281+
}
1282+
1283+
# wrapper function to create junction links
1284+
# Required to handle docker/for-win#12240
1285+
function New-DirectoryJunction($source, $target) {
1286+
if (Test-IsInsideContainer) {
1287+
& "$env:COMSPEC" /c "mklink /j `"$source`" `"$target`"" | out-null
1288+
} else {
1289+
New-Item -Path $source -ItemType Junction -Value $target | Out-Null
1290+
}
1291+
attrib $source +R /L
1292+
}
1293+

lib/psmodules.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function install_psmodule($manifest, $dir, $global) {
2626
Remove-Item -Path $linkfrom -Force -ErrorAction SilentlyContinue
2727
}
2828

29-
New-Item -Path $linkfrom -ItemType Junction -Value $dir | Out-Null
29+
New-DirectoryJunction $linkfrom $dir
3030
}
3131

3232
function uninstall_psmodule($manifest, $dir, $global) {

0 commit comments

Comments
 (0)