1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 12:41:46 +00:00

fix: address Copilot review feedback for dev cleanup

- Use age-based cleanup (90 days) for Cabal packages instead of clearing all
- Skip Mix archives cleanup to preserve globally installed tools
- Use age-based cleanup for Hex packages instead of clearing all
- Use age-based cleanup for Stack programs (GHC installations)
- Remove workspaceStorage from VS Code cleanup to preserve workspace settings
- Add missing cache paths for VS Code Insiders (CachedExtensions, etc.)

These changes make cleanup less aggressive and prevent accidental removal
of user-installed tools and workspace preferences.
This commit is contained in:
Bhadra
2026-01-12 10:59:16 +05:30
parent 7ea1ecdea2
commit 017a1311b8

View File

@@ -422,10 +422,12 @@ function Clear-ElixirCaches {
Clean Elixir Mix and Hex caches
#>
# Mix archives cache
# Mix archives - skip auto-cleanup to preserve globally installed Mix tools
# NOTE: This directory contains globally installed Mix tools and tasks (e.g., phx_new, hex).
# Clearing it would remove user-installed tools requiring reinstallation.
$mixArchivesPath = "$env:USERPROFILE\.mix\archives"
if (Test-Path $mixArchivesPath) {
Clear-DirectoryContents -Path $mixArchivesPath -Description "Mix archives cache"
Write-Debug "Skipping Mix archives at '$mixArchivesPath' - contains globally installed tools"
}
# Hex cache
@@ -434,10 +436,17 @@ function Clear-ElixirCaches {
Clear-DirectoryContents -Path $hexCachePath -Description "Hex cache"
}
# Hex packages
# Hex packages - use age-based cleanup to preserve actively used packages
$hexPackagesPath = "$env:USERPROFILE\.hex\packages"
if (Test-Path $hexPackagesPath) {
Clear-DirectoryContents -Path $hexPackagesPath -Description "Hex packages cache"
$cutoffDate = (Get-Date).AddDays(-90)
$oldHexPackages = Get-ChildItem -Path $hexPackagesPath -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.LastWriteTime -lt $cutoffDate }
if ($oldHexPackages) {
foreach ($pkg in $oldHexPackages) {
Remove-SafeItem -Path $pkg.FullName -Description "Old Hex package ($($pkg.Name))" -Recurse
}
}
}
}
@@ -451,10 +460,16 @@ function Clear-HaskellCaches {
Clean Haskell Cabal and Stack caches
#>
# Cabal packages cache
# Cabal packages cache - use age-based cleanup to preserve recently used packages
$cabalPackagesPath = "$env:USERPROFILE\.cabal\packages"
if (Test-Path $cabalPackagesPath) {
Clear-DirectoryContents -Path $cabalPackagesPath -Description "Cabal packages cache"
$cutoffDate = (Get-Date).AddDays(-90)
$oldCacheItems = Get-ChildItem -Path $cabalPackagesPath -Recurse -File -ErrorAction SilentlyContinue |
Where-Object { $_.LastWriteTime -lt $cutoffDate }
if ($oldCacheItems) {
$paths = $oldCacheItems | ForEach-Object { $_.FullName }
Remove-SafeItems -Paths $paths -Description "Cabal old packages cache"
}
}
# Cabal store
@@ -470,10 +485,18 @@ function Clear-HaskellCaches {
}
}
# Stack programs cache
# Stack programs cache - use age-based cleanup (contains GHC installations)
# These can be large and time-consuming to re-download
$stackProgramsPath = "$env:USERPROFILE\.stack\programs"
if (Test-Path $stackProgramsPath) {
Clear-DirectoryContents -Path $stackProgramsPath -Description "Stack programs cache"
$cutoffDate = (Get-Date).AddDays(-90)
$oldProgramDirs = Get-ChildItem -Path $stackProgramsPath -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.LastWriteTime -lt $cutoffDate }
if ($oldProgramDirs) {
foreach ($dir in $oldProgramDirs) {
Remove-SafeItem -Path $dir.FullName -Description "Stack old program ($($dir.Name))" -Recurse
}
}
}
# Stack snapshots (be careful - these are needed for builds)
@@ -525,6 +548,7 @@ function Clear-EditorCaches {
#>
# VS Code cached data
# NOTE: workspaceStorage excluded - contains workspace-specific settings and extension data
$vscodeCachePaths = @(
"$env:APPDATA\Code\Cache"
"$env:APPDATA\Code\CachedData"
@@ -532,7 +556,6 @@ function Clear-EditorCaches {
"$env:APPDATA\Code\CachedExtensionVSIXs"
"$env:APPDATA\Code\Code Cache"
"$env:APPDATA\Code\GPUCache"
"$env:APPDATA\Code\User\workspaceStorage"
"$env:LOCALAPPDATA\Microsoft\vscode-cpptools"
)
foreach ($path in $vscodeCachePaths) {
@@ -542,10 +565,14 @@ function Clear-EditorCaches {
}
# VS Code Insiders
# NOTE: workspaceStorage excluded - contains workspace-specific settings and extension data
$vscodeInsidersCachePaths = @(
"$env:APPDATA\Code - Insiders\Cache"
"$env:APPDATA\Code - Insiders\CachedData"
"$env:APPDATA\Code - Insiders\User\workspaceStorage"
"$env:APPDATA\Code - Insiders\CachedExtensions"
"$env:APPDATA\Code - Insiders\CachedExtensionVSIXs"
"$env:APPDATA\Code - Insiders\Code Cache"
"$env:APPDATA\Code - Insiders\GPUCache"
)
foreach ($path in $vscodeInsidersCachePaths) {
if (Test-Path $path) {