Skip to content

Commit

Permalink
feat(subdir): Allow subdir in 'bucket' (ScoopInstaller#5119)
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven authored Sep 28, 2022
1 parent 7a599f0 commit 7f47f66
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- **scoop-config:** Allow 'hold_update_until' be set manually ([#5100](https://github.com/ScoopInstaller/Scoop/issues/5100))
- **scoop-update:** Stash uncommitted changes before update ([#5091](https://github.com/ScoopInstaller/Scoop/issues/5091))
- **install:** Show the running process ([#5102](https://github.com/ScoopInstaller/Scoop/issues/5102))
- **subdir:** Allow subdir in 'bucket' ([#5119](https://github.com/ScoopInstaller/Scoop/issues/5119))

### Bug Fixes

Expand Down
10 changes: 6 additions & 4 deletions bin/checkhashes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ function err ([String] $name, [String[]] $message) {
}

$MANIFESTS = @()
foreach ($single in Get-ChildItem $Dir "$App.json") {
$name = (strip_ext $single.Name)
$manifest = parse_json "$Dir\$($single.Name)"
foreach ($single in Get-ChildItem $Dir -Filter "$App.json" -Recurse) {
$name = $single.BaseName
$file = $single.FullName
$manifest = parse_json $file

# Skip nighly manifests, since their hash validation is skipped
if ($manifest.version -eq 'nightly') { continue }
Expand Down Expand Up @@ -94,6 +95,7 @@ foreach ($single in Get-ChildItem $Dir "$App.json") {

$MANIFESTS += @{
app = $name
file = $file
manifest = $manifest
urls = $urls
hashes = $hashes
Expand Down Expand Up @@ -180,7 +182,7 @@ foreach ($current in $MANIFESTS) {
Write-Host "Writing updated $($current.app) manifest" -ForegroundColor DarkGreen

$current.manifest = $current.manifest | ConvertToPrettyJson
$path = Convert-Path "$Dir\$($current.app).json"
$path = Convert-Path $current.file
[System.IO.File]::WriteAllLines($path, $current.manifest)
}
}
8 changes: 4 additions & 4 deletions bin/checkurls.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ param(
$Dir = Convert-Path $Dir
$Queue = @()

Get-ChildItem $Dir "$App.json" | ForEach-Object {
$manifest = parse_json "$Dir\$($_.Name)"
$Queue += , @($_.Name, $manifest)
Get-ChildItem $Dir -Filter "$App.json" -Recurse | ForEach-Object {
$manifest = parse_json $_.FullName
$Queue += , @($_.BaseName, $manifest)
}

Write-Host '[' -NoNewLine
Expand Down Expand Up @@ -133,7 +133,7 @@ foreach ($man in $Queue) {
Write-Host $failed -NoNewLine -ForegroundColor Red
}
Write-Host '] ' -NoNewLine
Write-Host (strip_ext $name)
Write-Host $name

$errors | ForEach-Object {
Write-Host " > $_" -ForegroundColor DarkRed
Expand Down
19 changes: 11 additions & 8 deletions bin/checkver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ param(

if ($App -ne '*' -and (Test-Path $App -PathType Leaf)) {
$Dir = Split-Path $App
$files = Get-ChildItem $Dir (Split-Path $App -Leaf)
$files = Get-ChildItem $Dir -Filter (Split-Path $App -Leaf)
} elseif ($Dir) {
$Dir = Convert-Path $Dir
$files = Get-ChildItem $Dir "$App.json"
$files = Get-ChildItem $Dir -Filter "$App.json" -Recurse
} else {
throw "'-Dir' parameter required if '-App' is not a filepath!"
}
Expand All @@ -97,9 +97,10 @@ if ($App -eq '*' -and $Version -ne '') {
$Queue = @()
$json = ''
$files | ForEach-Object {
$json = parse_json "$Dir\$($_.Name)"
$file = $_.FullName
$json = parse_json $file
if ($json.checkver) {
$Queue += , @($_.Name, $json)
$Queue += , @($_.BaseName, $json, $file)
}
}

Expand All @@ -109,7 +110,7 @@ Get-EventSubscriber | Unregister-Event

# start all downloads
$Queue | ForEach-Object {
$name, $json = $_
$name, $json, $file = $_

$substitutions = Get-VersionSubstitution $json.version # 'autoupdate.ps1'

Expand Down Expand Up @@ -226,7 +227,8 @@ $Queue | ForEach-Object {
$url = substitute $url $substitutions

$state = New-Object psobject @{
app = (strip_ext $name);
app = $name;
file = $file;
url = $url;
regex = $regex;
json = $json;
Expand Down Expand Up @@ -254,6 +256,7 @@ while ($in_progress -gt 0) {

$state = $ev.SourceEventArgs.UserState
$app = $state.app
$file = $state.file
$json = $state.json
$url = $state.url
$regexp = $state.regex
Expand Down Expand Up @@ -360,7 +363,7 @@ while ($in_progress -gt 0) {
# Skip actual only if versions are same and there is no -f
if (($ver -eq $expected_ver) -and !$ForceUpdate -and $SkipUpdated) { continue }

Write-Host "$App`: " -NoNewline
Write-Host "$app`: " -NoNewline

# version hasn't changed (step over if forced update)
if ($ver -eq $expected_ver -and !$ForceUpdate) {
Expand All @@ -386,7 +389,7 @@ while ($in_progress -gt 0) {
Write-Host 'Forcing autoupdate!' -ForegroundColor DarkMagenta
}
try {
Invoke-AutoUpdate $App $Dir $json $ver $matchesHashtable # 'autoupdate.ps1'
Invoke-AutoUpdate $app $file $json $ver $matchesHashtable # 'autoupdate.ps1'
} catch {
if ($ThrowError) {
throw $_
Expand Down
6 changes: 3 additions & 3 deletions bin/describe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ param(
$Dir = Convert-Path $Dir
$Queue = @()

Get-ChildItem $Dir "$App.json" | ForEach-Object {
$manifest = parse_json "$Dir\$($_.Name)"
$Queue += , @(($_.Name -replace '\.json$', ''), $manifest)
Get-ChildItem $Dir -Filter "$App.json" -Recurse | ForEach-Object {
$manifest = parse_json $_.FullName
$Queue += , @($_.BaseName, $manifest)
}

$Queue | ForEach-Object {
Expand Down
9 changes: 4 additions & 5 deletions bin/formatjson.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ param(

$Dir = Convert-Path $Dir

Get-ChildItem $Dir "$App.json" | ForEach-Object {
if ($PSVersionTable.PSVersion.Major -gt 5) { $_ = $_.Name } # Fix for pwsh

Get-ChildItem $Dir -Filter "$App.json" -Recurse | ForEach-Object {
$file = $_.FullName
# beautify
$json = parse_json "$Dir\$_" | ConvertToPrettyJson
$json = parse_json $file | ConvertToPrettyJson

# convert to 4 spaces
$json = $json -replace "`t", ' '
[System.IO.File]::WriteAllLines("$Dir\$_", $json)
[System.IO.File]::WriteAllLines($file, $json)
}
6 changes: 3 additions & 3 deletions bin/missing-checkver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Write-Host 'A' -NoNewLine -ForegroundColor Cyan
Write-Host ']utoupdate'
Write-Host ' | |'

Get-ChildItem $Dir "$App.json" | ForEach-Object {
$json = parse_json "$Dir\$($_.Name)"
Get-ChildItem $Dir -Filter "$App.json" -Recurse | ForEach-Object {
$json = parse_json $_.FullName

if ($SkipSupported -and $json.checkver -and $json.autoupdate) { return }

Expand All @@ -48,5 +48,5 @@ Get-ChildItem $Dir "$App.json" | ForEach-Object {
Write-Host '[' -NoNewLine
Write-Host $(if ($json.autoupdate) { 'A' } else { ' ' }) -NoNewLine -ForegroundColor Cyan
Write-Host '] ' -NoNewLine
Write-Host (strip_ext $_.Name)
Write-Host $_.BaseName
}
2 changes: 1 addition & 1 deletion lib/autoupdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ function Invoke-AutoUpdate {
# 'Set-Content -Encoding ASCII' don't works in PowerShell 5
# Wait for 'UTF8NoBOM' Encoding in PowerShell 7
# $Manifest | ConvertToPrettyJson | Set-Content -Path (Join-Path $Path "$AppName.json") -Encoding UTF8NoBOM
[System.IO.File]::WriteAllLines((Join-Path $Path "$AppName.json"), (ConvertToPrettyJson $Manifest))
[System.IO.File]::WriteAllLines($Path, (ConvertToPrettyJson $Manifest))
# notes
$note = "`nUpdating note:"
if ($Manifest.autoupdate.note) {
Expand Down
2 changes: 1 addition & 1 deletion lib/buckets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function known_buckets {
}

function apps_in_bucket($dir) {
return Get-ChildItem $dir | Where-Object { $_.Name.EndsWith('.json') } | ForEach-Object { $_.Name -replace '.json$', '' }
return (Get-ChildItem $dir -Filter '*.json' -Recurse).BaseName
}

function Get-LocalBucket {
Expand Down
10 changes: 5 additions & 5 deletions lib/manifest.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function manifest_path($app, $bucket) {
fullpath "$(Find-BucketDirectory $bucket)\$(sanitary_path $app).json"
(Get-ChildItem (Find-BucketDirectory $bucket) -Filter "$(sanitary_path $app).json" -Recurse).FullName
}

function parse_json($path) {
if (!(Test-Path $path)) { return $null }
if ($null -eq $path -or !(Test-Path $path)) { return $null }
try {
Get-Content $path -Raw -Encoding UTF8 | ConvertFrom-Json -ErrorAction Stop
} catch {
Expand Down Expand Up @@ -142,10 +142,10 @@ function generate_user_manifest($app, $bucket, $version) {
abort "'$app' does not have autoupdate capability`r`ncouldn't find manifest for '$app@$version'"
}

ensure $(usermanifestsdir) | out-null
ensure (usermanifestsdir) | out-null
try {
Invoke-AutoUpdate $app "$(Convert-Path (usermanifestsdir))" $manifest $version $(@{ })
return "$(Convert-Path (usermanifest $app))"
Invoke-AutoUpdate $app "$(Convert-Path (usermanifestsdir))\$app.json" $manifest $version $(@{ })
return Convert-Path (usermanifest $app)
} catch {
write-host -f darkred "Could not install $app@$version"
}
Expand Down
2 changes: 1 addition & 1 deletion test/Import-Bucket-Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Describe 'manifest validates against the schema' -Tag 'Manifests' {
}
$changed_manifests = (Get-GitChangedFile -Path $repo_dir -Include '*.json' -Commit $commit)
}
$manifest_files = Get-ChildItem $bucketdir *.json
$manifest_files = Get-ChildItem $bucketdir -Filter '*.json' -Recurse
$validator = New-Object Scoop.Validator($schema, $true)
}

Expand Down

0 comments on commit 7f47f66

Please sign in to comment.