From f1f7733e55573057b33bdc944326fffe4791d9ea Mon Sep 17 00:00:00 2001 From: Kinshuk Bairagi Date: Tue, 22 Mar 2022 20:11:48 +0530 Subject: [PATCH] Fix symlinks inside containers --- CHANGELOG.md | 1 + lib/install.ps1 | 15 +++++++++++++-- lib/psmodules.ps1 | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5211269ce..79d65c2bcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/install.ps1 b/lib/install.ps1 index 3c8b2ec5de..f12c1990d6 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -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 } @@ -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 @@ -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 + } +} diff --git a/lib/psmodules.ps1 b/lib/psmodules.ps1 index fc32e99425..dcaf38818f 100644 --- a/lib/psmodules.ps1 +++ b/lib/psmodules.ps1 @@ -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) {