From 1de9bbd589820c5717a47dfbe586bfe4901ab245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LY=EF=BC=88=E9=80=80=E7=BD=91/offline=EF=BC=89?= <51789698+Young-Lord@users.noreply.github.com> Date: Tue, 9 Jul 2024 12:52:45 +0800 Subject: [PATCH] fix(install)!: show fs type and abort if Junction creation fails (#5367) --- CHANGELOG.md | 1 + lib/install.ps1 | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6d00c0239..f3c937368d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - **sqlite:** Fix compatibility with Windows PowerShell ([#6045](https://github.com/ScoopInstaller/Scoop/issues/6045)) - **install:** Expand `env_set` items before setting Environment Variables ([#6050](https://github.com/ScoopInstaller/Scoop/issues/6050)) +- **install:** Show filesystem type and abort if Junction creation fails ([#5367](https://github.com/ScoopInstaller/Scoop/discussions/5367)) - **bucket:** Implement error handling for failed bucket addition ([#6051](https://github.com/ScoopInstaller/Scoop/issues/6051)) ## [v0.5.0](https://github.com/ScoopInstaller/Scoop/compare/v0.4.2...v0.5.0) - 2024-07-01 diff --git a/lib/install.ps1 b/lib/install.ps1 index 6c8c3ff11a..3f1dd0da2e 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -1120,9 +1120,21 @@ function test_running_process($app, $global) { # 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 + try { + if (Get-Service -Name cexecsvc -ErrorAction SilentlyContinue) { + cmd.exe /d /c "mklink /j `"$source`" `"$target`"" + if ($lastexitcode -gt 0) { + throw System.ComponentModel.Win32Exception + } + } else { + New-Item -Path $source -ItemType Junction -Value $target -ErrorAction Stop + } + } + catch [System.ComponentModel.Win32Exception] { + # for non-NTFS filesystem, Junction creation may fail; in this case, showing FileSystemType helps to locate the issue + $target_path = Resolve-Path $target + $drive_letter = (Split-Path -Path $target_path -Qualifier).Trim(":") + warn "FileSystemType of target path $($target_path): $((Get-Volume -DriveLetter $drive_letter).FileSystemType)" + abort "Cannot link $(friendly_path $source) => $(friendly_path $target)" } }