Skip to content

Commit 3321b96

Browse files
authored
refactor(Get-Manifest): Select actual source for manifest (#6142)
* first step * Revert "first step" This reverts commit c5907c3. * refactor(Get-Manifest): Select actual source for installed manifest * rework sub-commands, `scoop-depends` is NOT working at this stage * URI manifest * opt * deprecated manifest * source of manifests * source of manifest pt2 - Mark URI(path/URL/UNC/etc.) query as standalone manifest - Drop `installed` and `available update` items for [query] and [installed] are different sources. * remove variable preventing I forget it * scoop-info: fix source of manifest on bucket * fix `scoop-depends` * Fix Standalone and Source detection * fix global install * Fix scoop-cat, scoop-home - Query for remote manifest * scoop-list: info +deprecated * manifest: Fix first selected manifest * gramma.. * Fix 61b3259 * length
1 parent 22f1672 commit 3321b96

10 files changed

Lines changed: 144 additions & 40 deletions

lib/core.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,9 @@ function app_status($app, $global) {
554554
$status.failed = failed $app $global
555555
$status.hold = ($install_info.hold -eq $true)
556556

557+
$deprecated_dir = (Find-BucketDirectory -Name $install_info.bucket -Root) + "\deprecated"
558+
$status.deprecated = (Get-ChildItem $deprecated_dir -Filter "$(sanitary_path $app).json" -Recurse).FullName
559+
557560
$manifest = manifest $app $install_info.bucket $install_info.url
558561
$status.removed = (!$manifest)
559562
if ($manifest.version) {
@@ -581,7 +584,6 @@ function app_status($app, $global) {
581584
if ($deps) {
582585
$status.missing_deps += , $deps
583586
}
584-
585587
return $status
586588
}
587589

lib/manifest.ps1

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,74 @@ function Get-Manifest($app) {
4040
$app = appname_from_url $url
4141
$manifest = url_manifest $url
4242
} else {
43-
$app, $bucket, $version = parse_app $app
44-
if ($bucket) {
45-
$manifest = manifest $app $bucket
46-
} else {
47-
foreach ($tekcub in Get-LocalBucket) {
48-
$manifest = manifest $app $tekcub
49-
if ($manifest) {
50-
$bucket = $tekcub
51-
break
43+
# Check if the manifest is already installed
44+
if (installed $app) {
45+
$global = installed $app $true
46+
$ver = Select-CurrentVersion -AppName $app -Global:$global
47+
if (!$ver) {
48+
$app, $bucket, $ver = parse_app $app
49+
$ver = Select-CurrentVersion -AppName $app -Global:$global
50+
}
51+
$install_info_path = "$(versiondir $app $ver $global)\install.json"
52+
if (Test-Path $install_info_path) {
53+
$install_info = parse_json $install_info_path
54+
$bucket = $install_info.bucket
55+
if (!$bucket) {
56+
$url = $install_info.url
57+
if ($url -match '^(ht|f)tps?://|\\\\') {
58+
$manifest = url_manifest $url
59+
}
60+
if (!$manifest) {
61+
if (Test-Path $url) {
62+
$manifest = parse_json $url
63+
} else {
64+
# Fallback to installed manifest
65+
$manifest = installed_manifest $app $ver $global
66+
}
67+
}
68+
} else {
69+
$manifest = manifest $app $bucket
70+
if (!$manifest) {
71+
$deprecated_dir = (Find-BucketDirectory -Name $bucket -Root) + '\deprecated'
72+
$manifest = parse_json (Get-ChildItem $deprecated_dir -Filter "$(sanitary_path $app).json" -Recurse).FullName
73+
}
5274
}
5375
}
54-
}
55-
if (!$manifest) {
56-
# couldn't find app in buckets: check if it's a local path
57-
if (Test-Path $app) {
58-
$url = Convert-Path $app
59-
$app = appname_from_url $url
60-
$manifest = url_manifest $url
76+
} else {
77+
$app, $bucket, $version = parse_app $app
78+
if ($bucket) {
79+
$manifest = manifest $app $bucket
6180
} else {
62-
if (($app -match '\\/') -or $app.EndsWith('.json')) { $url = $app }
63-
$app = appname_from_url $app
81+
$matched_buckets = @()
82+
foreach ($tekcub in Get-LocalBucket) {
83+
$current_manifest = manifest $app $tekcub
84+
if (!$manifest -and $current_manifest) {
85+
$manifest = $current_manifest
86+
$bucket = $tekcub
87+
}
88+
if ($current_manifest) {
89+
$matched_buckets += $tekcub
90+
}
91+
}
92+
}
93+
if (!$manifest) {
94+
# couldn't find app in buckets: check if it's a local path
95+
if (Test-Path $app) {
96+
$url = Convert-Path $app
97+
$app = appname_from_url $url
98+
$manifest = parse_json $url
99+
} else {
100+
if (($app -match '\\/') -or $app.EndsWith('.json')) { $url = $app }
101+
$app = appname_from_url $app
102+
}
64103
}
65104
}
66105
}
106+
107+
if ($matched_buckets.Length -gt 1) {
108+
warn "Multiple buckets contain manifest '$app', the current selection is '$bucket/$app'."
109+
}
110+
67111
return $app, $manifest, $bucket, $url
68112
}
69113

libexec/scoop-cat.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
param($app)
88

99
. "$PSScriptRoot\..\lib\json.ps1" # 'ConvertToPrettyJson'
10+
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
1011
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest'
12+
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-UserAgent'
1113

1214
if (!$app) { error '<app> missing'; my_usage; exit 1 }
1315

libexec/scoop-depends.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
. "$PSScriptRoot\..\lib\getopt.ps1"
55
. "$PSScriptRoot\..\lib\depends.ps1" # 'Get-Dependency'
6+
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
67
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest' (indirectly)
8+
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-UserAgent'
79

810
$opt, $apps, $err = getopt $args 'a:' 'arch='
911
$app = $apps[0]
@@ -20,7 +22,14 @@ try {
2022
$deps = @()
2123
Get-Dependency $app $architecture | ForEach-Object {
2224
$dep = [ordered]@{}
23-
$dep.Source, $dep.Name = $_ -split '/'
25+
26+
$app, $null, $bucket, $url = Get-Manifest $_
27+
if (!$url) {
28+
$bucket, $app = $_ -split '/'
29+
}
30+
$dep.Source = if ($url) { $url } else { $bucket }
31+
$dep.Name = $app
32+
2433
$deps += [PSCustomObject]$dep
2534
}
2635
$deps

libexec/scoop-download.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
. "$PSScriptRoot\..\lib\getopt.ps1"
2323
. "$PSScriptRoot\..\lib\json.ps1" # 'autoupdate.ps1' (indirectly)
2424
. "$PSScriptRoot\..\lib\autoupdate.ps1" # 'generate_user_manifest' (indirectly)
25+
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
2526
. "$PSScriptRoot\..\lib\manifest.ps1" # 'generate_user_manifest' 'Get-Manifest'
2627
. "$PSScriptRoot\..\lib\download.ps1"
2728
if (get_config USE_SQLITE_CACHE) {

libexec/scoop-home.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# Summary: Opens the app homepage
33
param($app)
44

5+
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
56
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest'
7+
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-UserAgent'
68

79
if ($app) {
810
$null, $manifest, $bucket, $null = Get-Manifest $app

libexec/scoop-info.ps1

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
. "$PSScriptRoot\..\lib\getopt.ps1"
77
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest'
8-
. "$PSScriptRoot\..\lib\versions.ps1" # 'Get-InstalledVersion'
8+
. "$PSScriptRoot\..\lib\versions.ps1" # 'Get-InstalledVersion', 'Select-CurrentVersion'
99
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-RemoteFileSize'
1010

1111
$opt, $app, $err = getopt $args 'v' 'verbose'
12+
$original_app = $app
1213
if ($err) { error "scoop info: $err"; exit 1 }
1314
$verbose = $opt.v -or $opt.verbose
1415

@@ -23,42 +24,78 @@ if (!$manifest) {
2324
$global = installed $app $true
2425
$status = app_status $app $global
2526
$install = install_info $app $status.version $global
26-
$status.installed = $bucket -and $install.bucket -eq $bucket
27+
$status.installed = ($bucket -and $install.bucket -eq $bucket) -or (installed $app)
2728
$version_output = $manifest.version
2829
$manifest_file = if ($bucket) {
2930
manifest_path $app $bucket
3031
} else {
3132
$url
3233
}
3334

35+
# Standalone and Source detection
36+
if ((Test-Path $original_app) -or ($original_app -match '^(ht|f)tps?://|\\\\')) {
37+
$standalone = $true
38+
if (Test-Path $original_app) {
39+
$original_app = (Get-AbsolutePath "$original_app")
40+
}
41+
if ($install.url) {
42+
if (Test-Path $install.url) {
43+
$install_url = (Get-AbsolutePath $install.url)
44+
} else {
45+
$install_url = $install.url
46+
}
47+
}
48+
if ($original_app -eq $install_url) {
49+
$same_source = $true
50+
}
51+
}
52+
3453
if ($verbose) {
3554
$dir = currentdir $app $global
3655
$original_dir = versiondir $app $manifest.version $global
3756
$persist_dir = persistdir $app $global
3857
} else {
39-
$dir, $original_dir, $persist_dir = "<root>", "<root>", "<root>"
58+
$dir, $original_dir, $persist_dir = '<root>', '<root>', '<root>'
4059
}
4160

4261
if ($status.installed) {
4362
$manifest_file = manifest_path $app $install.bucket
4463
if ($install.url) {
4564
$manifest_file = $install.url
4665
}
47-
if ($status.version -eq $manifest.version) {
66+
if ($status.deprecated) {
67+
$manifest_file = $status.deprecated
68+
} elseif ($standalone -and !$same_source) {
69+
$version_output = $manifest.version
70+
} elseif ($status.version -eq $manifest.version) {
4871
$version_output = $status.version
4972
} else {
5073
$version_output = "$($status.version) (Update to $($manifest.version) available)"
5174
}
75+
5276
}
5377

5478
$item = [ordered]@{ Name = $app }
79+
if ($status.deprecated) {
80+
$item.Name += ' (DEPRECATED)'
81+
}
5582
if ($manifest.description) {
5683
$item.Description = $manifest.description
5784
}
5885
$item.Version = $version_output
59-
if ($bucket) {
60-
$item.Bucket = $bucket
86+
87+
$item.Source = if ($standalone) {
88+
$original_app
89+
} else {
90+
if ($install.bucket) {
91+
$install.bucket
92+
} elseif ($install.url) {
93+
$install.url
94+
} else {
95+
$bucket
96+
}
6197
}
98+
6299
if ($manifest.homepage) {
63100
$item.Website = $manifest.homepage.TrimEnd('/')
64101
}
@@ -70,7 +107,7 @@ if ($manifest.license) {
70107
$manifest.license
71108
} elseif ($manifest.license -match '[|,]') {
72109
if ($verbose) {
73-
"$($manifest.license) ($(($manifest.license -Split "\||," | ForEach-Object { "https://spdx.org/licenses/$_.html" }) -join ', '))"
110+
"$($manifest.license) ($(($manifest.license -Split '\||,' | ForEach-Object { "https://spdx.org/licenses/$_.html" }) -join ', '))"
74111
} else {
75112
$manifest.license
76113
}
@@ -101,11 +138,13 @@ if ($verbose) { $item.Manifest = $manifest_file }
101138

102139
if ($status.installed) {
103140
# Show installed versions
104-
$installed_output = @()
105-
Get-InstalledVersion -AppName $app -Global:$global | ForEach-Object {
106-
$installed_output += if ($verbose) { versiondir $app $_ $global } else { "$_$(if ($global) { " *global*" })" }
141+
if (!$standalone -or $same_source) {
142+
$installed_output = @()
143+
Get-InstalledVersion -AppName $app -Global:$global | ForEach-Object {
144+
$installed_output += if ($verbose) { versiondir $app $_ $global } else { "$_$(if ($global) { ' *global*' })" }
145+
}
146+
$item.Installed = $installed_output -join "`n"
107147
}
108-
$item.Installed = $installed_output -join "`n"
109148

110149
if ($verbose) {
111150
# Show size of installation
@@ -162,7 +201,7 @@ if ($status.installed) {
162201
foreach ($url in @(url $manifest (Get-DefaultArchitecture))) {
163202
try {
164203
if (Test-Path (cache_path $app $manifest.version $url)) {
165-
$cached = " (latest version is cached)"
204+
$cached = ' (latest version is cached)'
166205
} else {
167206
$cached = $null
168207
}
@@ -197,15 +236,15 @@ if ($binaries) {
197236
$binary_output += $_
198237
}
199238
}
200-
$item.Binaries = $binary_output -join " | "
239+
$item.Binaries = $binary_output -join ' | '
201240
}
202241
$shortcuts = @(arch_specific 'shortcuts' $manifest $install.architecture)
203242
if ($shortcuts) {
204243
$shortcut_output = @()
205244
$shortcuts | ForEach-Object {
206245
$shortcut_output += $_[1]
207246
}
208-
$item.Shortcuts = $shortcut_output -join " | "
247+
$item.Shortcuts = $shortcut_output -join ' | '
209248
}
210249
$env_set = arch_specific 'env_set' $manifest $install.architecture
211250
if ($env_set) {

libexec/scoop-list.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ param($query)
55

66
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
77
. "$PSScriptRoot\..\lib\manifest.ps1" # 'parse_json' 'Select-CurrentVersion' (indirectly)
8+
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-UserAgent'
89

9-
$def_arch = Get-DefaultArchitecture
10+
$defaultArchitecture = Get-DefaultArchitecture
1011
if (-not (Get-FormatData ScoopApps)) {
1112
Update-FormatData "$PSScriptRoot\..\supporting\formats\ScoopTypes.Format.ps1xml"
1213
}
@@ -47,10 +48,11 @@ $apps | Where-Object { !$query -or ($_.name -match $query) } | ForEach-Object {
4748
$item.Updated = $updated
4849

4950
$info = @()
51+
if ((app_status $app $global).deprecated) { $info += 'Deprecated package'}
5052
if ($global) { $info += 'Global install' }
5153
if (failed $app $global) { $info += 'Install failed' }
5254
if ($install_info.hold) { $info += 'Held package' }
53-
if ($install_info.architecture -and $def_arch -ne $install_info.architecture) {
55+
if ($install_info.architecture -and $defaultArchitecture -ne $install_info.architecture) {
5456
$info += $install_info.architecture
5557
}
5658
$item.Info = $info -join ', '

libexec/scoop-status.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
. "$PSScriptRoot\..\lib\manifest.ps1" # 'manifest' 'parse_json' "install_info"
88
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
9+
. "$PSScriptRoot\..\lib\download.ps1" # 'Get-UserAgent'
910

1011
# check if scoop needs updating
1112
$currentdir = versiondir 'scoop' 'current'
@@ -58,17 +59,18 @@ $true, $false | ForEach-Object { # local and global apps
5859
Get-ChildItem $dir | Where-Object name -NE 'scoop' | ForEach-Object {
5960
$app = $_.name
6061
$status = app_status $app $global
61-
if (!$status.outdated -and !$status.failed -and !$status.removed -and !$status.missing_deps) { return }
62+
if (!$status.outdated -and !$status.failed -and !$status.deprecated -and !$status.removed -and !$status.missing_deps) { return }
6263

6364
$item = [ordered]@{}
6465
$item.Name = $app
6566
$item.'Installed Version' = $status.version
6667
$item.'Latest Version' = if ($status.outdated) { $status.latest_version } else { "" }
6768
$item.'Missing Dependencies' = $status.missing_deps -Split ' ' -Join ' | '
6869
$info = @()
69-
if ($status.failed) { $info += 'Install failed' }
70-
if ($status.hold) { $info += 'Held package' }
71-
if ($status.removed) { $info += 'Manifest removed' }
70+
if ($status.failed) { $info += 'Install failed' }
71+
if ($status.hold) { $info += 'Held package' }
72+
if ($status.deprecated) { $info += 'Deprecated' }
73+
if ($status.removed) { $info += 'Manifest removed' }
7274
$item.Info = $info -join ', '
7375
$list += [PSCustomObject]$item
7476
}

libexec/scoop-virustotal.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
# -p, --passthru Return reports as objects
3030

3131
. "$PSScriptRoot\..\lib\getopt.ps1"
32+
. "$PSScriptRoot\..\lib\versions.ps1" # 'Select-CurrentVersion'
3233
. "$PSScriptRoot\..\lib\manifest.ps1" # 'Get-Manifest'
3334
. "$PSScriptRoot\..\lib\json.ps1" # 'json_path'
3435
. "$PSScriptRoot\..\lib\download.ps1" # 'hash_for_url'

0 commit comments

Comments
 (0)