Skip to content

Commit a831bd6

Browse files
committed
- Get-PogDownloadCache: Clean up filtering
1 parent ae2a967 commit a831bd6

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

app/Pog/Pog.psm1

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,20 @@ class DownloadCacheEntry {
211211
hidden [string]$Path
212212
}
213213

214+
filter ListEntries($FilterSb) {
215+
foreach ($Source in $_.SourcePackages | ? $FilterSb) {
216+
[DownloadCacheEntry]@{
217+
PackageName = $Source.PackageName
218+
Version = $Source.ManifestVersion
219+
Hash = $_.EntryKey
220+
FileName = [System.IO.Path]::GetFileName($_.Path)
221+
222+
Size = $_.Size
223+
Path = [System.IO.Path]::GetDirectoryName($_.Path)
224+
}
225+
}
226+
}
227+
214228
function Get-PogDownloadCache {
215229
[CmdletBinding(PositionalBinding=$false)]
216230
[OutputType([DownloadCacheEntry])]
@@ -224,33 +238,17 @@ function Get-PogDownloadCache {
224238
begin {
225239
$Entries = [array][Pog.InternalState]::DownloadCache.EnumerateEntries()
226240

227-
function ListEntries($FilterSb) {
228-
foreach ($Entry in $Entries) {
229-
foreach ($Source in $Entry.SourcePackages | ? $FilterSb) {
230-
[DownloadCacheEntry]@{
231-
PackageName = $Source.PackageName
232-
Version = $Source.ManifestVersion
233-
Hash = $Entry.EntryKey
234-
FileName = [System.IO.Path]::GetFileName($Entry.Path)
235-
236-
Size = $Entry.Size
237-
Path = [System.IO.Path]::GetDirectoryName($Entry.Path)
238-
}
239-
}
240-
}
241-
}
242-
243241
if (-not $MyInvocation.ExpectingInput -and -not $PackageName) {
244-
ListEntries {$true}
242+
$Entries | ListEntries {$true}
245243
}
246244
}
247245

248246
process {
249247
foreach ($pn in $PackageName) {
250-
$Result = ListEntries {$_.PackageName -eq $pn}
251-
echo $Result
252-
253-
if (-not $Result) {
248+
$Result = $Entries | ListEntries {$_.PackageName -eq $pn}
249+
if ($Result) {
250+
echo $Result
251+
} else {
254252
# hacky way to create an ErrorRecord
255253
$e = try {throw "No download cache entries found for package '$pn'."} catch {$_}
256254
$PSCmdlet.WriteError($e)

0 commit comments

Comments
 (0)