diff --git a/internal/pkg/cleanup/cleanup.go b/internal/pkg/cleanup/cleanup.go index c63b804..e66c306 100644 --- a/internal/pkg/cleanup/cleanup.go +++ b/internal/pkg/cleanup/cleanup.go @@ -1,4 +1,4 @@ -// Copyright 2026 MarketAlly. All rights reserved. +// Copyright 2026 MarketAlly. All rights reserved. // SPDX-License-Identifier: MIT package cleanup @@ -276,44 +276,52 @@ func cleanBuildCaches(maxAge time.Duration) (int64, int, error) { var totalFilesDeleted int // Build cache directories to clean - // Format: {path, description} + // Format: {path, description, maxAge (0 = use default)} + // Go build cache cleaned more aggressively (3 days) as it grows very fast + goBuildMaxAge := 3 * 24 * time.Hour cacheDirs := []struct { - path string - desc string + path string + desc string + maxAge time.Duration }{ // Linux paths - {filepath.Join(home, ".cache", "go-build"), "Go build cache"}, - {filepath.Join(home, ".cache", "golangci-lint"), "golangci-lint cache"}, - {filepath.Join(home, ".npm", "_cacache"), "npm cache"}, - {filepath.Join(home, ".cache", "pnpm"), "pnpm cache"}, - {filepath.Join(home, ".cache", "yarn"), "yarn cache"}, - {filepath.Join(home, ".nuget", "packages"), "NuGet cache"}, - {filepath.Join(home, ".gradle", "caches"), "Gradle cache"}, - {filepath.Join(home, ".m2", "repository"), "Maven cache"}, - {filepath.Join(home, ".cache", "pip"), "pip cache"}, - {filepath.Join(home, ".cargo", "registry", "cache"), "Cargo cache"}, - {filepath.Join(home, ".rustup", "tmp"), "Rustup temp"}, + {filepath.Join(home, ".cache", "go-build"), "Go build cache", goBuildMaxAge}, + {filepath.Join(home, ".cache", "golangci-lint"), "golangci-lint cache", 0}, + {filepath.Join(home, ".npm", "_cacache"), "npm cache", 0}, + {filepath.Join(home, ".cache", "pnpm"), "pnpm cache", 0}, + {filepath.Join(home, ".cache", "yarn"), "yarn cache", 0}, + {filepath.Join(home, ".nuget", "packages"), "NuGet cache", 0}, + {filepath.Join(home, ".gradle", "caches"), "Gradle cache", 0}, + {filepath.Join(home, ".m2", "repository"), "Maven cache", 0}, + {filepath.Join(home, ".cache", "pip"), "pip cache", 0}, + {filepath.Join(home, ".cargo", "registry", "cache"), "Cargo cache", 0}, + {filepath.Join(home, ".rustup", "tmp"), "Rustup temp", 0}, // macOS paths (Library/Caches) - {filepath.Join(home, "Library", "Caches", "go-build"), "Go build cache (macOS)"}, - {filepath.Join(home, "Library", "Caches", "Yarn"), "Yarn cache (macOS)"}, - {filepath.Join(home, "Library", "Caches", "pip"), "pip cache (macOS)"}, - {filepath.Join(home, "Library", "Caches", "Homebrew"), "Homebrew cache (macOS)"}, + {filepath.Join(home, "Library", "Caches", "go-build"), "Go build cache (macOS)", goBuildMaxAge}, + {filepath.Join(home, "Library", "Caches", "Yarn"), "Yarn cache (macOS)", 0}, + {filepath.Join(home, "Library", "Caches", "pip"), "pip cache (macOS)", 0}, + {filepath.Join(home, "Library", "Caches", "Homebrew"), "Homebrew cache (macOS)", 0}, // Windows paths (LOCALAPPDATA) - {filepath.Join(os.Getenv("LOCALAPPDATA"), "go-build"), "Go build cache (Windows)"}, - {filepath.Join(os.Getenv("LOCALAPPDATA"), "npm-cache"), "npm cache (Windows)"}, - {filepath.Join(os.Getenv("LOCALAPPDATA"), "pnpm"), "pnpm cache (Windows)"}, - {filepath.Join(os.Getenv("LOCALAPPDATA"), "Yarn", "Cache"), "Yarn cache (Windows)"}, - {filepath.Join(os.Getenv("LOCALAPPDATA"), "NuGet", "v3-cache"), "NuGet cache (Windows)"}, - {filepath.Join(os.Getenv("LOCALAPPDATA"), "pip", "Cache"), "pip cache (Windows)"}, + {filepath.Join(os.Getenv("LOCALAPPDATA"), "go-build"), "Go build cache (Windows)", goBuildMaxAge}, + {filepath.Join(os.Getenv("LOCALAPPDATA"), "npm-cache"), "npm cache (Windows)", 0}, + {filepath.Join(os.Getenv("LOCALAPPDATA"), "pnpm"), "pnpm cache (Windows)", 0}, + {filepath.Join(os.Getenv("LOCALAPPDATA"), "Yarn", "Cache"), "Yarn cache (Windows)", 0}, + {filepath.Join(os.Getenv("LOCALAPPDATA"), "NuGet", "v3-cache"), "NuGet cache (Windows)", 0}, + {filepath.Join(os.Getenv("LOCALAPPDATA"), "pip", "Cache"), "pip cache (Windows)", 0}, } - cutoff := time.Now().Add(-maxAge) - for _, cache := range cacheDirs { if _, err := os.Stat(cache.path); os.IsNotExist(err) { continue } + // Use cache-specific maxAge if set, otherwise use default + cacheMaxAge := cache.maxAge + if cacheMaxAge == 0 { + cacheMaxAge = maxAge + } + cutoff := time.Now().Add(-cacheMaxAge) + var bytesFreed int64 var filesDeleted int