Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scoop-info): Show app installed/download size #4886

Merged
merged 20 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- **update:** Skip logs starting with `(chore)` ([#4800](https://github.com/ScoopInstaller/Scoop/issues/4800))
- **scoop-download:** Add failure check ([#4822](https://github.com/ScoopInstaller/Scoop/pull/4822))
- **install:** Fix issue with installation inside containers ([#4837](https://github.com/ScoopInstaller/Scoop/pull/4837))
- **scoop-info:** Display a breakdown of an app's installation size, or the download size if not installed (`--verbose` only) ([#4840](https://github.com/ScoopInstaller/Scoop/issues/4840))
- **bucket:** Return empty list correctly in `Get-LocalBucket` ([#4885](https://github.com/ScoopInstaller/Scoop/pull/4885))

### Performance Improvements
Expand Down
75 changes: 75 additions & 0 deletions libexec/scoop-info.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,81 @@ if ($status.installed) {
$installed_output += if ($verbose) { versiondir $app $_ $global } else { "$_$(if ($global) { " *global*" })" }
}
$item.Installed = $installed_output -join "`n"

if ($verbose) {
# Show size of installation
$appsdir = appsdir $global

$appFiles = Get-ChildItem $appsdir | Where-Object -Property Name -Value "^$app$" -Match
$persistFiles = Get-ChildItem $persist_dir -ErrorAction Ignore # Will fail if app does not persist data
$cacheFiles = Get-ChildItem $cachedir | Where-Object -Property Name -Value "^$app#" -Match

$totalSize = 0
$fileTotals = @()
foreach ($fileType in ($appFiles, $persistFiles, $cacheFiles)) {
if ($fileType.Length -ne 0) {
tech189 marked this conversation as resolved.
Show resolved Hide resolved
$fileSum = (Get-ChildItem $fileType -Recurse | Measure-Object -Property Length -Sum).Sum
$fileTotals += $fileSum
$totalSize += $fileSum
tech189 marked this conversation as resolved.
Show resolved Hide resolved
}
else {
tech189 marked this conversation as resolved.
Show resolved Hide resolved
$fileTotals += 0
}
}

$item.'Installed size' = "App: $(filesize $fileTotals[0])`nPersist: $(filesize $fileTotals[1])`nCache: $(filesize $fileTotals[2])`nTotal: $(filesize $totalSize)"
}
}
else {
tech189 marked this conversation as resolved.
Show resolved Hide resolved
if ($verbose) {
# Get download size if app not installed
$architecture = default_architecture

if(!(supports_architecture $manifest $architecture)) {
# No available download for current architecture
continue
}

if ($null -eq $manifest.url) {
# use url for current architecture
$urls = url $manifest $architecture
}
else {
tech189 marked this conversation as resolved.
Show resolved Hide resolved
# otherwise use non-architecture url
$urls = $manifest.url
}

$totalPackage = 0
foreach($url in $urls) {
tech189 marked this conversation as resolved.
Show resolved Hide resolved
try {
[int]$urlLength = (Invoke-WebRequest $url -Method Head).Headers.'Content-Length'[0]
$totalPackage += $urlLength

if (Test-Path (fullpath (cache_path $app $manifest.version $url))) {
$cached = " (latest version is cached)"
}
else {
tech189 marked this conversation as resolved.
Show resolved Hide resolved
$cached = $null
}
}
catch [System.Management.Automation.RuntimeException] {
tech189 marked this conversation as resolved.
Show resolved Hide resolved
$totalPackage = 0
$packageError = "the server at $(([System.Uri]$url).Host) did not send a Content-Length header"
break
}
catch {
tech189 marked this conversation as resolved.
Show resolved Hide resolved
$totalPackage = 0
$packageError = "the server at $(([System.Uri]$url).Host) is down"
break
}
}
if ($totalPackage -ne 0) {
$item.'Download size' = "$(filesize $totalPackage)$cached"
}
else {
tech189 marked this conversation as resolved.
Show resolved Hide resolved
$item.'Download size' = "Unknown ($packageError)"
}
}
}

$binaries = @(arch_specific 'bin' $manifest $install.architecture)
Expand Down