Skip to content

Commit 5b6d126

Browse files
niheavense35710
authored andcommitted
fix(no-junction): Fix error when 'NO_JUNCTIONS' is been set (ScoopInstaller#4722)
1 parent 043dd76 commit 5b6d126

8 files changed

Lines changed: 79 additions & 50 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- **installed:** Fix 'core/installed' that mark failed app as 'installed' ([#4650](https://github.com/ScoopInstaller/Scoop/issues/4650))
2121
- **status:** Correctly handle failed installation of apps ([#4676](https://github.com/ScoopInstaller/Scoop/issues/4676))
2222
- **test:** Import 'versions.ps1' in `Scoop-Decompress.Tests.ps1` ([#4689](https://github.com/ScoopInstaller/Scoop/issues/4689))
23+
- **no-junctions:** Fix error when `NO_JUNCTIONS` is been set ([#4722](https://github.com/ScoopInstaller/Scoop/issues/4722))
2324
- **shim:** Fix PS1 shim error when in different drive in PS7 ([#4614](https://github.com/ScoopInstaller/Scoop/issues/4614))
2425
- **shim:** Fix `sh` shim error in WSL ([#4637](https://github.com/ScoopInstaller/Scoop/issues/4637))
2526
- **versions:** Fix wrong version number when only one version dir ([#4679](https://github.com/ScoopInstaller/Scoop/issues/4679))

lib/core.ps1

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ function appsdir($global) { "$(basedir $global)\apps" }
187187
function shimdir($global) { "$(basedir $global)\shims" }
188188
function appdir($app, $global) { "$(appsdir $global)\$app" }
189189
function versiondir($app, $version, $global) { "$(appdir $app $global)\$version" }
190+
191+
function currentdir($app, $global) {
192+
if (get_config NO_JUNCTIONS) {
193+
$version = Select-CurrentVersion -App $app -Global:$global
194+
} else {
195+
$version = 'current'
196+
}
197+
"$(appdir $app $global)\$version"
198+
}
199+
190200
function persistdir($app, $global) { "$(basedir $global)\persist\$app" }
191201
function usermanifestsdir { "$(basedir)\workspace" }
192202
function usermanifest($app) { "$(usermanifestsdir)\$app.json" }
@@ -223,6 +233,7 @@ function file_path($app, $file) {
223233

224234
function Get-AppFilePath {
225235
[CmdletBinding()]
236+
[OutputType([String])]
226237
param(
227238
[Parameter(Mandatory = $true, Position = 0)]
228239
[String]
@@ -233,13 +244,13 @@ function Get-AppFilePath {
233244
)
234245

235246
# normal path to file
236-
$Path = "$(versiondir $App 'current' $false)\$File"
247+
$Path = "$(currentdir $App $false)\$File"
237248
if (Test-Path $Path) {
238249
return $Path
239250
}
240251

241252
# global path to file
242-
$Path = "$(versiondir $App 'current' $true)\$File"
253+
$Path = "$(currentdir $App $true)\$File"
243254
if (Test-Path $Path) {
244255
return $Path
245256
}
@@ -257,34 +268,38 @@ Function Test-CommandAvailable {
257268

258269
function Get-HelperPath {
259270
[CmdletBinding()]
271+
[OutputType([String])]
260272
param(
261273
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
262274
[ValidateSet('7zip', 'Lessmsi', 'Innounp', 'Dark', 'Aria2', 'Zstd')]
263275
[String]
264276
$Helper
265277
)
266-
267-
$HelperPath = $null
268-
switch ($Helper) {
269-
'7zip' {
270-
$HelperPath = Get-AppFilePath '7zip' '7z.exe'
271-
if ([String]::IsNullOrEmpty($HelperPath)) {
272-
$HelperPath = Get-AppFilePath '7zip-zstd' '7z.exe'
278+
begin {
279+
$HelperPath = $null
280+
}
281+
process {
282+
switch ($Helper) {
283+
'7zip' {
284+
$HelperPath = Get-AppFilePath '7zip' '7z.exe'
285+
if ([String]::IsNullOrEmpty($HelperPath)) {
286+
$HelperPath = Get-AppFilePath '7zip-zstd' '7z.exe'
287+
}
273288
}
274-
}
275-
'Lessmsi' { $HelperPath = Get-AppFilePath 'lessmsi' 'lessmsi.exe' }
276-
'Innounp' { $HelperPath = Get-AppFilePath 'innounp' 'innounp.exe' }
277-
'Dark' {
278-
$HelperPath = Get-AppFilePath 'dark' 'dark.exe'
279-
if ([String]::IsNullOrEmpty($HelperPath)) {
280-
$HelperPath = Get-AppFilePath 'wixtoolset' 'dark.exe'
289+
'Lessmsi' { $HelperPath = Get-AppFilePath 'lessmsi' 'lessmsi.exe' }
290+
'Innounp' { $HelperPath = Get-AppFilePath 'innounp' 'innounp.exe' }
291+
'Dark' {
292+
$HelperPath = Get-AppFilePath 'dark' 'dark.exe'
293+
if ([String]::IsNullOrEmpty($HelperPath)) {
294+
$HelperPath = Get-AppFilePath 'wixtoolset' 'dark.exe'
295+
}
281296
}
297+
'Aria2' { $HelperPath = Get-AppFilePath 'aria2' 'aria2c.exe' }
298+
'Zstd' { $HelperPath = Get-AppFilePath 'zstd' 'zstd.exe' }
282299
}
283-
'Aria2' { $HelperPath = Get-AppFilePath 'aria2' 'aria2c.exe' }
284-
'Zstd' { $HelperPath = Get-AppFilePath 'zstd' 'zstd.exe' }
285-
}
286300

287-
return $HelperPath
301+
return $HelperPath
302+
}
288303
}
289304

290305
function Test-HelperInstalled {
@@ -545,10 +560,14 @@ function movedir($from, $to) {
545560
}
546561

547562
function get_app_name($path) {
548-
if ($path -match '([^/\\]+)[/\\]current[/\\]') {
549-
return $matches[1].tolower()
563+
if ((Test-Path (appsdir $false)) -and ($path -match "$([Regex]::Escape($(Convert-Path (appsdir $false))))[/\\]([^/\\]+)")) {
564+
$appName = $Matches[1].ToLower()
565+
} elseif ((Test-Path (appsdir $true)) -and ($path -match "$([Regex]::Escape($(Convert-Path (appsdir $true))))[/\\]([^/\\]+)")) {
566+
$appName = $Matches[1].ToLower()
567+
} else {
568+
$appName = ''
550569
}
551-
return ''
570+
return $appName
552571
}
553572

554573
function get_app_name_from_shim($shim) {

lib/install.ps1

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -897,23 +897,15 @@ function rm_shims($manifest, $global, $arch) {
897897
}
898898
}
899899

900-
# Gets the path for the 'current' directory junction for
901-
# the specified version directory.
902-
function current_dir($versiondir) {
903-
$parent = split-path $versiondir
904-
return "$parent\current"
905-
}
906-
907-
908900
# Creates or updates the directory junction for [app]/current,
909901
# pointing to the specified version directory for the app.
910902
#
911903
# Returns the 'current' junction directory if in use, otherwise
912904
# the version directory.
913905
function link_current($versiondir) {
914-
if (get_config NO_JUNCTIONS) { return $versiondir }
906+
if (get_config NO_JUNCTIONS) { return $versiondir.ToString() }
915907

916-
$currentdir = current_dir $versiondir
908+
$currentdir = "$(Split-Path $versiondir)\current"
917909

918910
Write-Host "Linking $(friendly_path $currentdir) => $(friendly_path $versiondir)"
919911

@@ -938,8 +930,8 @@ function link_current($versiondir) {
938930
# Returns the 'current' junction directory (if it exists),
939931
# otherwise the normal version directory.
940932
function unlink_current($versiondir) {
941-
if (get_config NO_JUNCTIONS) { return $versiondir }
942-
$currentdir = current_dir $versiondir
933+
if (get_config NO_JUNCTIONS) { return $versiondir.ToString() }
934+
$currentdir = "$(Split-Path $versiondir)\current"
943935

944936
if (Test-Path $currentdir) {
945937
Write-Host "Unlinking $(friendly_path $currentdir)"

libexec/scoop-hold.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ $apps | ForEach-Object {
2222
return
2323
}
2424

25-
$dir = versiondir $app 'current' $global
26-
$json = install_info $app 'current' $global
25+
if (get_config NO_JUNCTIONS) {
26+
$version = Select-CurrentVersion -App $app -Global:$global
27+
} else {
28+
$version = 'current'
29+
}
30+
$dir = versiondir $app $version $global
31+
$json = install_info $app $version $global
2732
$install = @{}
2833
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name))}
2934
$install.hold = $true

libexec/scoop-info.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if (!$manifest_file) {
4141
$manifest_file = manifest_path $app $bucket
4242
}
4343

44-
$dir = versiondir $app 'current' $global
44+
$dir = currentdir $app $global
4545
$original_dir = versiondir $app $manifest.version $global
4646
$persist_dir = persistdir $app $global
4747

libexec/scoop-prefix.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
param($app)
44

55
if (!$app) {
6-
. "$psscriptroot\..\lib\help.ps1"
6+
. "$PSScriptRoot\..\lib\help.ps1"
77
my_usage
88
exit 1
99
}
1010

11-
. "$psscriptroot\..\lib\core.ps1"
11+
. "$PSScriptRoot\..\lib\core.ps1"
12+
. "$PSScriptRoot\..\lib\versions.ps1"
1213

13-
$app_path = versiondir $app 'current' $false
14+
$app_path = currentdir $app $false
1415
if (!(Test-Path $app_path)) {
15-
$app_path = versiondir $app 'current' $true
16+
$app_path = currentdir $app$true
1617
}
1718

1819
if (Test-Path $app_path) {

libexec/scoop-unhold.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ $apps | ForEach-Object {
2222
return
2323
}
2424

25-
$dir = versiondir $app 'current' $global
26-
$json = install_info $app 'current' $global
25+
if (get_config NO_JUNCTIONS) {
26+
$version = Select-CurrentVersion -App $app -Global:$global
27+
} else {
28+
$version = 'current'
29+
}
30+
$dir = versiondir $app $version $global
31+
$json = install_info $app $version $global
2732
$install = @{}
2833
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name))}
2934
$install.hold = $null

test/Scoop-Core.Tests.ps1

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ $isUnix = is_unix
99
Describe 'Get-AppFilePath' -Tag 'Scoop' {
1010
BeforeAll {
1111
$working_dir = setup_working 'is_directory'
12-
Mock versiondir { 'local' } -Verifiable -ParameterFilter { $global -eq $false }
13-
Mock versiondir { 'global' } -Verifiable -ParameterFilter { $global -eq $true }
12+
Mock currentdir { 'local' } -Verifiable -ParameterFilter { $global -eq $false }
13+
Mock currentdir { 'global' } -Verifiable -ParameterFilter { $global -eq $true }
1414
}
1515

1616
It 'should return locally installed program' {
@@ -226,6 +226,7 @@ Describe 'get_app_name_from_shim' -Tag 'Scoop' {
226226
$working_dir = setup_working 'shim'
227227
$shimdir = shimdir
228228
$(ensure_in_path $shimdir) | Out-Null
229+
Mock appsdir { $working_dir }
229230
}
230231

231232
It 'returns empty string if file does not exist' -Skip:$isUnix {
@@ -234,10 +235,15 @@ Describe 'get_app_name_from_shim' -Tag 'Scoop' {
234235

235236
It 'returns app name if file exists and is a shim to an app' -Skip:$isUnix {
236237
mkdir -p "$working_dir/mockapp/current/"
237-
Write-Output '' | Out-File "$working_dir/mockapp/current/mockapp.ps1"
238-
shim "$working_dir/mockapp/current/mockapp.ps1" $false 'shim-test'
239-
$shim_path = (Get-Command 'shim-test.ps1').Path
240-
get_app_name_from_shim "$shim_path" | Should -Be 'mockapp'
238+
Write-Output '' | Out-File "$working_dir/mockapp/current/mockapp1.ps1"
239+
shim "$working_dir/mockapp/current/mockapp1.ps1" $false 'shim-test1'
240+
$shim_path1 = (Get-Command 'shim-test1.ps1').Path
241+
get_app_name_from_shim "$shim_path1" | Should -Be 'mockapp'
242+
mkdir -p "$working_dir/mockapp/1.0.0/"
243+
Write-Output '' | Out-File "$working_dir/mockapp/1.0.0/mockapp2.ps1"
244+
shim "$working_dir/mockapp/1.0.0/mockapp2.ps1" $false 'shim-test2'
245+
$shim_path2 = (Get-Command 'shim-test2.ps1').Path
246+
get_app_name_from_shim "$shim_path2" | Should -Be 'mockapp'
241247
}
242248

243249
It 'returns empty string if file exists and is not a shim' -Skip:$isUnix {

0 commit comments

Comments
 (0)