Skip to content

Commit 7f47f66

Browse files
authored
feat(subdir): Allow subdir in 'bucket' (#5119)
1 parent 7a599f0 commit 7f47f66

File tree

11 files changed

+40
-35
lines changed

11 files changed

+40
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- **scoop-config:** Allow 'hold_update_until' be set manually ([#5100](https://github.com/ScoopInstaller/Scoop/issues/5100))
99
- **scoop-update:** Stash uncommitted changes before update ([#5091](https://github.com/ScoopInstaller/Scoop/issues/5091))
1010
- **install:** Show the running process ([#5102](https://github.com/ScoopInstaller/Scoop/issues/5102))
11+
- **subdir:** Allow subdir in 'bucket' ([#5119](https://github.com/ScoopInstaller/Scoop/issues/5119))
1112

1213
### Bug Fixes
1314

bin/checkhashes.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ function err ([String] $name, [String[]] $message) {
6060
}
6161

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

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

9596
$MANIFESTS += @{
9697
app = $name
98+
file = $file
9799
manifest = $manifest
98100
urls = $urls
99101
hashes = $hashes
@@ -180,7 +182,7 @@ foreach ($current in $MANIFESTS) {
180182
Write-Host "Writing updated $($current.app) manifest" -ForegroundColor DarkGreen
181183

182184
$current.manifest = $current.manifest | ConvertToPrettyJson
183-
$path = Convert-Path "$Dir\$($current.app).json"
185+
$path = Convert-Path $current.file
184186
[System.IO.File]::WriteAllLines($path, $current.manifest)
185187
}
186188
}

bin/checkurls.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ param(
3333
$Dir = Convert-Path $Dir
3434
$Queue = @()
3535

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

4141
Write-Host '[' -NoNewLine
@@ -133,7 +133,7 @@ foreach ($man in $Queue) {
133133
Write-Host $failed -NoNewLine -ForegroundColor Red
134134
}
135135
Write-Host '] ' -NoNewLine
136-
Write-Host (strip_ext $name)
136+
Write-Host $name
137137

138138
$errors | ForEach-Object {
139139
Write-Host " > $_" -ForegroundColor DarkRed

bin/checkver.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ param(
7878

7979
if ($App -ne '*' -and (Test-Path $App -PathType Leaf)) {
8080
$Dir = Split-Path $App
81-
$files = Get-ChildItem $Dir (Split-Path $App -Leaf)
81+
$files = Get-ChildItem $Dir -Filter (Split-Path $App -Leaf)
8282
} elseif ($Dir) {
8383
$Dir = Convert-Path $Dir
84-
$files = Get-ChildItem $Dir "$App.json"
84+
$files = Get-ChildItem $Dir -Filter "$App.json" -Recurse
8585
} else {
8686
throw "'-Dir' parameter required if '-App' is not a filepath!"
8787
}
@@ -97,9 +97,10 @@ if ($App -eq '*' -and $Version -ne '') {
9797
$Queue = @()
9898
$json = ''
9999
$files | ForEach-Object {
100-
$json = parse_json "$Dir\$($_.Name)"
100+
$file = $_.FullName
101+
$json = parse_json $file
101102
if ($json.checkver) {
102-
$Queue += , @($_.Name, $json)
103+
$Queue += , @($_.BaseName, $json, $file)
103104
}
104105
}
105106

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

110111
# start all downloads
111112
$Queue | ForEach-Object {
112-
$name, $json = $_
113+
$name, $json, $file = $_
113114

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

@@ -226,7 +227,8 @@ $Queue | ForEach-Object {
226227
$url = substitute $url $substitutions
227228

228229
$state = New-Object psobject @{
229-
app = (strip_ext $name);
230+
app = $name;
231+
file = $file;
230232
url = $url;
231233
regex = $regex;
232234
json = $json;
@@ -254,6 +256,7 @@ while ($in_progress -gt 0) {
254256

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

363-
Write-Host "$App`: " -NoNewline
366+
Write-Host "$app`: " -NoNewline
364367

365368
# version hasn't changed (step over if forced update)
366369
if ($ver -eq $expected_ver -and !$ForceUpdate) {
@@ -386,7 +389,7 @@ while ($in_progress -gt 0) {
386389
Write-Host 'Forcing autoupdate!' -ForegroundColor DarkMagenta
387390
}
388391
try {
389-
Invoke-AutoUpdate $App $Dir $json $ver $matchesHashtable # 'autoupdate.ps1'
392+
Invoke-AutoUpdate $app $file $json $ver $matchesHashtable # 'autoupdate.ps1'
390393
} catch {
391394
if ($ThrowError) {
392395
throw $_

bin/describe.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ param(
2727
$Dir = Convert-Path $Dir
2828
$Queue = @()
2929

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

3535
$Queue | ForEach-Object {

bin/formatjson.ps1

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ param(
3333

3434
$Dir = Convert-Path $Dir
3535

36-
Get-ChildItem $Dir "$App.json" | ForEach-Object {
37-
if ($PSVersionTable.PSVersion.Major -gt 5) { $_ = $_.Name } # Fix for pwsh
38-
36+
Get-ChildItem $Dir -Filter "$App.json" -Recurse | ForEach-Object {
37+
$file = $_.FullName
3938
# beautify
40-
$json = parse_json "$Dir\$_" | ConvertToPrettyJson
39+
$json = parse_json $file | ConvertToPrettyJson
4140

4241
# convert to 4 spaces
4342
$json = $json -replace "`t", ' '
44-
[System.IO.File]::WriteAllLines("$Dir\$_", $json)
43+
[System.IO.File]::WriteAllLines($file, $json)
4544
}

bin/missing-checkver.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ Write-Host 'A' -NoNewLine -ForegroundColor Cyan
3636
Write-Host ']utoupdate'
3737
Write-Host ' | |'
3838

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

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

@@ -48,5 +48,5 @@ Get-ChildItem $Dir "$App.json" | ForEach-Object {
4848
Write-Host '[' -NoNewLine
4949
Write-Host $(if ($json.autoupdate) { 'A' } else { ' ' }) -NoNewLine -ForegroundColor Cyan
5050
Write-Host '] ' -NoNewLine
51-
Write-Host (strip_ext $_.Name)
51+
Write-Host $_.BaseName
5252
}

lib/autoupdate.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ function Invoke-AutoUpdate {
449449
# 'Set-Content -Encoding ASCII' don't works in PowerShell 5
450450
# Wait for 'UTF8NoBOM' Encoding in PowerShell 7
451451
# $Manifest | ConvertToPrettyJson | Set-Content -Path (Join-Path $Path "$AppName.json") -Encoding UTF8NoBOM
452-
[System.IO.File]::WriteAllLines((Join-Path $Path "$AppName.json"), (ConvertToPrettyJson $Manifest))
452+
[System.IO.File]::WriteAllLines($Path, (ConvertToPrettyJson $Manifest))
453453
# notes
454454
$note = "`nUpdating note:"
455455
if ($Manifest.autoupdate.note) {

lib/buckets.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function known_buckets {
5050
}
5151

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

5656
function Get-LocalBucket {

lib/manifest.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function manifest_path($app, $bucket) {
2-
fullpath "$(Find-BucketDirectory $bucket)\$(sanitary_path $app).json"
2+
(Get-ChildItem (Find-BucketDirectory $bucket) -Filter "$(sanitary_path $app).json" -Recurse).FullName
33
}
44

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

145-
ensure $(usermanifestsdir) | out-null
145+
ensure (usermanifestsdir) | out-null
146146
try {
147-
Invoke-AutoUpdate $app "$(Convert-Path (usermanifestsdir))" $manifest $version $(@{ })
148-
return "$(Convert-Path (usermanifest $app))"
147+
Invoke-AutoUpdate $app "$(Convert-Path (usermanifestsdir))\$app.json" $manifest $version $(@{ })
148+
return Convert-Path (usermanifest $app)
149149
} catch {
150150
write-host -f darkred "Could not install $app@$version"
151151
}

0 commit comments

Comments
 (0)