Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(install): Fix Junction creation during installation inside containers #4837

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- **scoop-prefix:** Fix typo that breaks global installed apps ([#4795](https://github.com/ScoopInstaller/Scoop/issues/4795))
- **update:** Skip logs starting with `(chore)` ([#4800](https://github.com/ScoopInstaller/Scoop/issues/4800))
- **scoop-download:** Add failure check ([#4822](https://github.com/ScoopInstaller/Scoop/pull/4822))
- **install:** Fix issue with installation inside containers ([#4837](https://github.com/ScoopInstaller/Scoop/pull/4837))

### Code Refactoring

Expand Down
15 changes: 13 additions & 2 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,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 | Out-Null
attrib $currentdir +R /L
return $currentdir
}
Expand Down Expand Up @@ -1175,7 +1175,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 | Out-Null
attrib $source +R /L
} else {
# target is a file, create hard link
Expand Down Expand Up @@ -1238,3 +1238,14 @@ 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`""
} else {
New-Item -Path $source -ItemType Junction -Value $target
}
}
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 | Out-Null
}

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