@@ -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+
0 commit comments