Skip to content

Commit

Permalink
fix: Cache the arm check to prevent multiple calls of uname on *nix (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 committed Dec 14, 2021
1 parent 39791a8 commit 844a8f3
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 58 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

🎉🎉 YAML typed manifest and archived manifest installation support 🎉🎉

- Cache the arm check to prevent multiple calls of `uname` on *nix
- **Unix**: Fix `--version` command under *nix
- **scoop-uninstall**: Warn user when he tries to uninstall dependency, which is still needed
- **scoop-status**: Detect if applications, which were installed as dependency are still needed
- **scoop-list**: Show if application was installed as dependency
- If it was installed as dependency, the parent application will be shown as `{application}` in blue
- **scoop-list**:
- Fix detection of installed status for PowerShell 5
- Show if application was installed as dependency
- If it was installed as dependency, the parent application will be shown as `{application}` in blue
- Adopt new resolve function for parameter passing
- **scoop-install**
- **scoop-depends**
Expand Down
5 changes: 3 additions & 2 deletions bin/scoop.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ $ExitCode = 0
# ONLY if:
# - No command passed
# - -v or --version passed
$version = ($Command -eq '--version') -or (!$Command -and ($args.Contains('-v')))
# On *nix --version is passed in $args instead of command
$version = (($Command -eq '--version') -or ($args -eq '--version')) -or (!$Command -and ($args.Contains('-v')))

# Scoop itself help should be shown only if explicitly asked:
# - No version asked
Expand Down Expand Up @@ -51,7 +52,7 @@ if ($version) {
Get-LocalBucket | ForEach-Object {
$b = Find-BucketDirectory $_ -Root

if (Join-Path $b '.git' | Test-Path -PathType Container) {
if (Join-Path $b '.git' | Test-Path -PathType 'Container') {
Write-UserMessage -Message "'$_' bucket:" -Output
Invoke-GitCmd -Command 'VersionLog' -Repository $b
Write-UserMessage -Message '' -Output
Expand Down
2 changes: 1 addition & 1 deletion lib/Installation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Install-ScoopApplication {
$persist_dir = persistdir $appName $Global

# Suggest installing arm64
if ((Test-IsArmArchitecture) -and ($Architecture -ne 'arm64') -and ($manifest.'architecture'.'arm64')) {
if ($SHOVEL_IS_ARM_ARCH -and ($Architecture -ne 'arm64') -and ($manifest.'architecture'.'arm64')) {
Write-UserMessage -Message 'Manifest explicitly supports arm64. Consider to install using arm64 version to achieve best compatibility/performance.' -Success
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Update-ScoopCoreClone {
Invoke-GitCmd -Command 'clone' -Argument '--quiet', '--single-branch', '--branch', """$Branch""", $Repo, """$newDir""" -Proxy

# Check if scoop was successful downloaded
if (!(Test-Path $newDir -PathType Container)) { Stop-ScoopExecution -Message 'Scoop update failed.' }
if (!(Test-Path -LiteralPath $newDir -PathType 'Container')) { Stop-ScoopExecution -Message 'Scoop update failed.' }

# Replace non-git scoop with the git version
Remove-Item $TargetDirectory -ErrorAction 'Stop' -Force -Recurse
Expand Down
7 changes: 4 additions & 3 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ function Test-IsUnix {
.SYNOPSIS
Custom check to identify non-windows hosts.
.DESCRIPTION
$isWindows is not defind in PW5, thus null and boolean checks are needed.
$IsWindows is not defind in PW5, thus null and boolean checks are needed.
#>
[CmdletBinding()]
[OutputType([bool])]
param()

process { return !(($null -eq $isWindows) -or ($isWindows -eq $true)) }
process { return !(($null -eq $IsWindows) -or ($IsWindows -eq $true)) }
}

function Invoke-SystemComSpecCommand {
Expand Down Expand Up @@ -644,7 +644,7 @@ function shim($path, $global, $name, $arg) {

if ($path -match '\.(exe|com)$') {
# for programs with no awareness of any shell
$executableName = if (Test-IsArmArchitecture) { 'shim.arm64.exe' } else { 'shim.exe' }
$executableName = if ($SHOVEL_IS_ARM_ARCH) { 'shim.arm64.exe' } else { 'shim.exe' }
# TODO: Use relative path from this file
$shimExePath = versiondir 'scoop' 'current' | Join-Path -ChildPath "supporting\shimexe\bin\$executableName"

Expand Down Expand Up @@ -963,6 +963,7 @@ $SCOOP_CONFIGURATION = load_cfg $SCOOP_CONFIGURATION_FILE
# General variables
$SHOVEL_DEBUG_ENABLED = Test-ScoopDebugEnabled
$SHOVEL_IS_UNIX = Test-IsUnix
$SHOVEL_IS_ARM_ARCH = Test-IsArmArchitecture

# TODO: Remove deprecated variables
$scoopdir = $SCOOP_ROOT_DIRECTORY
Expand Down
93 changes: 46 additions & 47 deletions lib/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Deny-ArmInstallation {
param($Manifest, $Architecture)

process {
if (Test-IsArmArchitecture) {
if ($SHOVEL_IS_ARM_ARCH) {
if (($Architecture -eq 'arm64') -and !($Manifest.'architecture'.'arm64')) {
throw [ScoopException] "Manifest does not explicitly support 'arm64' architecture. Try to install with '--arch 32bit' or '--arch 64bit' to use Windows arm emulation."
}
Expand Down Expand Up @@ -1032,9 +1032,9 @@ function create_shims($manifest, $dir, $global, $arch) {
Write-UserMessage -Message "Creating shim for '$name'." -Output:$false

$bin = Join-Path $dir $target
if (Test-Path $bin -PathType Leaf) {
if (Test-Path -LiteralPath $bin -PathType 'Leaf') {
$bin = $bin
} elseif (Test-Path $target -PathType Leaf) {
} elseif (Test-Path -LiteralPath $target -PathType 'Leaf') {
$bin = $target
} else {
$bin = search_in_path $target
Expand All @@ -1060,7 +1060,7 @@ function rm_shim($name, $shimdir) {
# Other shim types might be present
'', '.exe', '.shim', '.cmd' | ForEach-Object {
$p = Join-Path $shimdir "$name$_"
if (Test-Path $p -PathType Leaf) { Remove-Item $p }
if (Test-Path -LiteralPath $p -PathType 'Leaf') { Remove-Item $p }
}
}

Expand Down Expand Up @@ -1119,7 +1119,7 @@ function unlink_current($versiondir) {
if (get_config 'NO_JUNCTIONS') { return $versiondir }
$currentdir = current_dir $versiondir

if (Test-Path $currentdir) {
if (Test-Path -LiteralPath $currentdir -PathType 'Container') {
Write-UserMessage -Message "Unlinking $(friendly_path $currentdir)" -Output:$false

# remove read-only attribute on link
Expand Down Expand Up @@ -1156,7 +1156,7 @@ function find_dir_or_subdir($path, $dir) {
$dir = $dir.TrimEnd('\')
$fixed = @()
$removed = @()
$path.Split(';') | ForEach-Object {
$path -split ';' | ForEach-Object {
if ($_) {
if (($_ -eq $dir) -or ($_ -like "$dir\*")) { $removed += $_ }
else { $fixed += $_ }
Expand Down Expand Up @@ -1304,57 +1304,56 @@ function persist_def($persist) {
}

function persist_data($manifest, $original_dir, $persist_dir) {
# TODO: Architecture specific persist?? Are there any apps, that would benefit?
$persist = $manifest.persist
if ($persist) {
$persist_dir = Confirm-DirectoryExistence -LiteralPath $persist_dir
if (!$persist) { return }

if ($persist -is [String]) {
$persist = @($persist);
}
$persist_dir = Confirm-DirectoryExistence -LiteralPath $persist_dir

$persist | ForEach-Object {
$source, $target = persist_def $_
if ($persist -is [String]) { $persist = @($persist) }

Write-UserMessage -Message "Persisting $source" -Output:$false
foreach ($p in $persist) {
$source, $target = persist_def $p

$source = $source.TrimEnd('/').TrimEnd('\\')
Write-UserMessage -Message "Persisting $source" -Output:$false

$source = Join-Path $original_dir $source
$target = Join-Path $persist_dir $target
$source = $source.TrimEnd('/').TrimEnd('\\')

# if we have had persist data in the store, just create link and go
if (Test-Path $target) {
# if there is also a source data, rename it (to keep a original backup)
if (Test-Path $source) {
Move-Item $source "$source.original" -Force
}
# we don't have persist data in the store, move the source to target, then create link
} elseif (Test-Path $source) {
# ensure target parent folder exist
Split-Path $target | Confirm-DirectoryExistence | Out-Null
Move-Item $source $target
# we don't have neither source nor target data! we need to crate an empty target,
# but we can't make a judgement that the data should be a file or directory...
# so we create a directory by default. to avoid this, use pre_install
# to create the source file before persisting (DO NOT use post_install)
} else {
$target = New-Object System.IO.DirectoryInfo($target)
Confirm-DirectoryExistence -LiteralPath $target | Out-Null
$source = Join-Path $original_dir $source
$target = Join-Path $persist_dir $target

# if we have had persist data in the store, just create link and go
if (Test-Path $target) {
# if there is also a source data, rename it (to keep a original backup)
if (Test-Path $source) {
Move-Item $source "$source.original" -Force
}
# we don't have persist data in the store, move the source to target, then create link
} elseif (Test-Path $source) {
# ensure target parent folder exist
Split-Path $target | Confirm-DirectoryExistence | Out-Null
Move-Item $source $target
# we don't have neither source nor target data! we need to crate an empty target,
# but we can't make a judgement that the data should be a file or directory...
# so we create a directory by default. to avoid this, use pre_install
# to create the source file before persisting (DO NOT use post_install)
} else {
$target = New-Object System.IO.DirectoryInfo($target)
Confirm-DirectoryExistence -LiteralPath $target | Out-Null
}

# Mklink throw 'The system cannot find the path specified.' if the full path of the link does not exist.
$splitted = Split-Path $source -Parent
if ($splitted -ne $original_dir) { Confirm-DirectoryExistence -LiteralPath $splitted | Out-Null }
# Mklink throw 'The system cannot find the path specified.' if the full path of the link does not exist.
$splitted = Split-Path $source -Parent
if ($splitted -ne $original_dir) { Confirm-DirectoryExistence -LiteralPath $splitted | Out-Null }

# create link
if (is_directory $target) {
# target is a directory, create junction
& "$env:COMSPEC" /c "mklink /j `"$source`" `"$target`"" | Out-Null
attrib $source +R /L
} else {
# target is a file, create hard link
& "$env:COMSPEC" /c "mklink /h `"$source`" `"$target`"" | Out-Null
}
# create link
if (is_directory $target) {
# target is a directory, create junction
& "$env:COMSPEC" /c "mklink /j `"$source`" `"$target`"" | Out-Null
attrib $source +R /L
} else {
# target is a file, create hard link
& "$env:COMSPEC" /c "mklink /h `"$source`" `"$target`"" | Out-Null
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ function installed_manifest($app, $version, $global) {

# Different extension types
if (!(Test-Path -LiteralPath $manifestPath -PathType 'Leaf')) {
$installedManifests = Get-ChildItem -LiteralPath $d -Include 'scoop-manifest.*' -ErrorAction 'SilentlyContinue'
$installedManifests = Get-ChildItem "$d\scoop-manifest.*" -ErrorAction 'SilentlyContinue'
if ($installedManifests.Count -gt 0) {
$manifestPath = $installedManifests[0].FullName
}
Expand Down Expand Up @@ -597,7 +597,7 @@ function default_architecture {
$arch = get_config 'default-architecture'
$system = if ([System.IntPtr]::Size -eq 8) { '64bit' } else { '32bit' }

if (Test-IsArmArchitecture) { $arch = 'arm' + ($system -replace 'bit') }
if ($SHOVEL_IS_ARM_ARCH) { $arch = 'arm' + ($system -replace 'bit') }

if ($null -eq $arch) {
$arch = $system
Expand Down
9 changes: 9 additions & 0 deletions test/Scoop-TestLib.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ function setup_working($name) {
exit 1
}

if (!$env:TEMP) {
$env:TEMP = 'C:\temp'
if ($IsWindows -eq $false) { $env:TEMP = '/tmp' }
}

if (!(Test-Path -LiteralPath $env:TEMP -PathType 'Container')) {
New-Item $env:TEMP -ItemType 'Directory' -Force
}

# reset working dir
$working_dir = "$env:TEMP/ScoopTestFixtures/$name"

Expand Down

0 comments on commit 844a8f3

Please sign in to comment.