-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cache): Add "tidy" as older cache removal command
- Keep two items in cache for every app - Files that are less than one month old are not deleted - Automatically remove older cache of the app after an update - Short option to do not use cache changed form `-k` to `-d` (for "download") - Add option to keep older cache, with `-k` (for "keep") as short option to `update` command - Add long option `--keep-cache` to `update` command
- Loading branch information
Showing
5 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Remove older cache of the given app | ||
function tidy_cache([String] $app, [bool] $total_log = $false) { | ||
if ($app -like "*.json") { return } | ||
|
||
# Dependencies of the format "bucket/dependency" install in a directory of form | ||
# "dependency". So we need to extract the bucket from the name and only use the app | ||
# name | ||
$app = ($app -split '/|\\')[-1] | ||
|
||
$files = @(Get-ChildItem $cachedir | Where-Object -Property Name -Value "^$app#" -Match | Sort-Object LastWriteTime ) | ||
if ($files.Count -le 2) { | ||
return | ||
} | ||
|
||
# do not remove last two files | ||
$files = $files[0..($files.Count - 3)] | ||
# remove only items more than one month old | ||
$files = $files| Where-Object {$_.LastWriteTime -lt (Get-Date).AddMonths(-1)} | ||
if ($files.Count -le 0) { | ||
if ($total_log) { Write-Host "Nothing to do" -ForegroundColor Yellow } | ||
return | ||
} | ||
Write-Host -f yellow "Removing older cache for $app`:" -NoNewline | ||
|
||
$totalLength = ($files | Measure-Object -Property Length -Sum).Sum | ||
$files | ForEach-Object { | ||
Write-Host " $(($_ -split '#')[1])" -NoNewline | ||
Remove-Item $_.FullName | ||
} | ||
|
||
Write-Host '' | ||
if ($total_log) { | ||
Write-Host "Deleted: $($files.Count) $(pluralize $files.Count 'file' 'files'), $(filesize $totalLength)" -ForegroundColor Yellow | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters