Skip to content

Commit

Permalink
fix(no-junction): Fix error when 'NO_JUNCTIONS' is been set (ScoopIns…
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven authored and se35710 committed Mar 8, 2022
1 parent 043dd76 commit 5b6d126
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- **installed:** Fix 'core/installed' that mark failed app as 'installed' ([#4650](https://github.com/ScoopInstaller/Scoop/issues/4650))
- **status:** Correctly handle failed installation of apps ([#4676](https://github.com/ScoopInstaller/Scoop/issues/4676))
- **test:** Import 'versions.ps1' in `Scoop-Decompress.Tests.ps1` ([#4689](https://github.com/ScoopInstaller/Scoop/issues/4689))
- **no-junctions:** Fix error when `NO_JUNCTIONS` is been set ([#4722](https://github.com/ScoopInstaller/Scoop/issues/4722))
- **shim:** Fix PS1 shim error when in different drive in PS7 ([#4614](https://github.com/ScoopInstaller/Scoop/issues/4614))
- **shim:** Fix `sh` shim error in WSL ([#4637](https://github.com/ScoopInstaller/Scoop/issues/4637))
- **versions:** Fix wrong version number when only one version dir ([#4679](https://github.com/ScoopInstaller/Scoop/issues/4679))
Expand Down
65 changes: 42 additions & 23 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ function appsdir($global) { "$(basedir $global)\apps" }
function shimdir($global) { "$(basedir $global)\shims" }
function appdir($app, $global) { "$(appsdir $global)\$app" }
function versiondir($app, $version, $global) { "$(appdir $app $global)\$version" }

function currentdir($app, $global) {
if (get_config NO_JUNCTIONS) {
$version = Select-CurrentVersion -App $app -Global:$global
} else {
$version = 'current'
}
"$(appdir $app $global)\$version"
}

function persistdir($app, $global) { "$(basedir $global)\persist\$app" }
function usermanifestsdir { "$(basedir)\workspace" }
function usermanifest($app) { "$(usermanifestsdir)\$app.json" }
Expand Down Expand Up @@ -223,6 +233,7 @@ function file_path($app, $file) {

function Get-AppFilePath {
[CmdletBinding()]
[OutputType([String])]
param(
[Parameter(Mandatory = $true, Position = 0)]
[String]
Expand All @@ -233,13 +244,13 @@ function Get-AppFilePath {
)

# normal path to file
$Path = "$(versiondir $App 'current' $false)\$File"
$Path = "$(currentdir $App $false)\$File"
if (Test-Path $Path) {
return $Path
}

# global path to file
$Path = "$(versiondir $App 'current' $true)\$File"
$Path = "$(currentdir $App $true)\$File"
if (Test-Path $Path) {
return $Path
}
Expand All @@ -257,34 +268,38 @@ Function Test-CommandAvailable {

function Get-HelperPath {
[CmdletBinding()]
[OutputType([String])]
param(
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
[ValidateSet('7zip', 'Lessmsi', 'Innounp', 'Dark', 'Aria2', 'Zstd')]
[String]
$Helper
)

$HelperPath = $null
switch ($Helper) {
'7zip' {
$HelperPath = Get-AppFilePath '7zip' '7z.exe'
if ([String]::IsNullOrEmpty($HelperPath)) {
$HelperPath = Get-AppFilePath '7zip-zstd' '7z.exe'
begin {
$HelperPath = $null
}
process {
switch ($Helper) {
'7zip' {
$HelperPath = Get-AppFilePath '7zip' '7z.exe'
if ([String]::IsNullOrEmpty($HelperPath)) {
$HelperPath = Get-AppFilePath '7zip-zstd' '7z.exe'
}
}
}
'Lessmsi' { $HelperPath = Get-AppFilePath 'lessmsi' 'lessmsi.exe' }
'Innounp' { $HelperPath = Get-AppFilePath 'innounp' 'innounp.exe' }
'Dark' {
$HelperPath = Get-AppFilePath 'dark' 'dark.exe'
if ([String]::IsNullOrEmpty($HelperPath)) {
$HelperPath = Get-AppFilePath 'wixtoolset' 'dark.exe'
'Lessmsi' { $HelperPath = Get-AppFilePath 'lessmsi' 'lessmsi.exe' }
'Innounp' { $HelperPath = Get-AppFilePath 'innounp' 'innounp.exe' }
'Dark' {
$HelperPath = Get-AppFilePath 'dark' 'dark.exe'
if ([String]::IsNullOrEmpty($HelperPath)) {
$HelperPath = Get-AppFilePath 'wixtoolset' 'dark.exe'
}
}
'Aria2' { $HelperPath = Get-AppFilePath 'aria2' 'aria2c.exe' }
'Zstd' { $HelperPath = Get-AppFilePath 'zstd' 'zstd.exe' }
}
'Aria2' { $HelperPath = Get-AppFilePath 'aria2' 'aria2c.exe' }
'Zstd' { $HelperPath = Get-AppFilePath 'zstd' 'zstd.exe' }
}

return $HelperPath
return $HelperPath
}
}

function Test-HelperInstalled {
Expand Down Expand Up @@ -545,10 +560,14 @@ function movedir($from, $to) {
}

function get_app_name($path) {
if ($path -match '([^/\\]+)[/\\]current[/\\]') {
return $matches[1].tolower()
if ((Test-Path (appsdir $false)) -and ($path -match "$([Regex]::Escape($(Convert-Path (appsdir $false))))[/\\]([^/\\]+)")) {
$appName = $Matches[1].ToLower()
} elseif ((Test-Path (appsdir $true)) -and ($path -match "$([Regex]::Escape($(Convert-Path (appsdir $true))))[/\\]([^/\\]+)")) {
$appName = $Matches[1].ToLower()
} else {
$appName = ''
}
return ''
return $appName
}

function get_app_name_from_shim($shim) {
Expand Down
16 changes: 4 additions & 12 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -897,23 +897,15 @@ function rm_shims($manifest, $global, $arch) {
}
}

# Gets the path for the 'current' directory junction for
# the specified version directory.
function current_dir($versiondir) {
$parent = split-path $versiondir
return "$parent\current"
}


# Creates or updates the directory junction for [app]/current,
# pointing to the specified version directory for the app.
#
# Returns the 'current' junction directory if in use, otherwise
# the version directory.
function link_current($versiondir) {
if (get_config NO_JUNCTIONS) { return $versiondir }
if (get_config NO_JUNCTIONS) { return $versiondir.ToString() }

$currentdir = current_dir $versiondir
$currentdir = "$(Split-Path $versiondir)\current"

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

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

if (Test-Path $currentdir) {
Write-Host "Unlinking $(friendly_path $currentdir)"
Expand Down
9 changes: 7 additions & 2 deletions libexec/scoop-hold.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ $apps | ForEach-Object {
return
}

$dir = versiondir $app 'current' $global
$json = install_info $app 'current' $global
if (get_config NO_JUNCTIONS) {
$version = Select-CurrentVersion -App $app -Global:$global
} else {
$version = 'current'
}
$dir = versiondir $app $version $global
$json = install_info $app $version $global
$install = @{}
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name))}
$install.hold = $true
Expand Down
2 changes: 1 addition & 1 deletion libexec/scoop-info.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if (!$manifest_file) {
$manifest_file = manifest_path $app $bucket
}

$dir = versiondir $app 'current' $global
$dir = currentdir $app $global
$original_dir = versiondir $app $manifest.version $global
$persist_dir = persistdir $app $global

Expand Down
9 changes: 5 additions & 4 deletions libexec/scoop-prefix.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
param($app)

if (!$app) {
. "$psscriptroot\..\lib\help.ps1"
. "$PSScriptRoot\..\lib\help.ps1"
my_usage
exit 1
}

. "$psscriptroot\..\lib\core.ps1"
. "$PSScriptRoot\..\lib\core.ps1"
. "$PSScriptRoot\..\lib\versions.ps1"

$app_path = versiondir $app 'current' $false
$app_path = currentdir $app $false
if (!(Test-Path $app_path)) {
$app_path = versiondir $app 'current' $true
$app_path = currentdir $app$true
}

if (Test-Path $app_path) {
Expand Down
9 changes: 7 additions & 2 deletions libexec/scoop-unhold.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ $apps | ForEach-Object {
return
}

$dir = versiondir $app 'current' $global
$json = install_info $app 'current' $global
if (get_config NO_JUNCTIONS) {
$version = Select-CurrentVersion -App $app -Global:$global
} else {
$version = 'current'
}
$dir = versiondir $app $version $global
$json = install_info $app $version $global
$install = @{}
$json | Get-Member -MemberType Properties | ForEach-Object { $install.Add($_.Name, $json.($_.Name))}
$install.hold = $null
Expand Down
18 changes: 12 additions & 6 deletions test/Scoop-Core.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ $isUnix = is_unix
Describe 'Get-AppFilePath' -Tag 'Scoop' {
BeforeAll {
$working_dir = setup_working 'is_directory'
Mock versiondir { 'local' } -Verifiable -ParameterFilter { $global -eq $false }
Mock versiondir { 'global' } -Verifiable -ParameterFilter { $global -eq $true }
Mock currentdir { 'local' } -Verifiable -ParameterFilter { $global -eq $false }
Mock currentdir { 'global' } -Verifiable -ParameterFilter { $global -eq $true }
}

It 'should return locally installed program' {
Expand Down Expand Up @@ -226,6 +226,7 @@ Describe 'get_app_name_from_shim' -Tag 'Scoop' {
$working_dir = setup_working 'shim'
$shimdir = shimdir
$(ensure_in_path $shimdir) | Out-Null
Mock appsdir { $working_dir }
}

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

It 'returns app name if file exists and is a shim to an app' -Skip:$isUnix {
mkdir -p "$working_dir/mockapp/current/"
Write-Output '' | Out-File "$working_dir/mockapp/current/mockapp.ps1"
shim "$working_dir/mockapp/current/mockapp.ps1" $false 'shim-test'
$shim_path = (Get-Command 'shim-test.ps1').Path
get_app_name_from_shim "$shim_path" | Should -Be 'mockapp'
Write-Output '' | Out-File "$working_dir/mockapp/current/mockapp1.ps1"
shim "$working_dir/mockapp/current/mockapp1.ps1" $false 'shim-test1'
$shim_path1 = (Get-Command 'shim-test1.ps1').Path
get_app_name_from_shim "$shim_path1" | Should -Be 'mockapp'
mkdir -p "$working_dir/mockapp/1.0.0/"
Write-Output '' | Out-File "$working_dir/mockapp/1.0.0/mockapp2.ps1"
shim "$working_dir/mockapp/1.0.0/mockapp2.ps1" $false 'shim-test2'
$shim_path2 = (Get-Command 'shim-test2.ps1').Path
get_app_name_from_shim "$shim_path2" | Should -Be 'mockapp'
}

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

0 comments on commit 5b6d126

Please sign in to comment.