1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 22:30:08 +00:00

fix(clean): respect whitelist when cleaning Go caches (#530)

- Add whitelist checking to clean_dev_go() function
- Check both GOCACHE and GOMODCACHE before cleaning
- Show appropriate messages for protected caches
- Fix whitelist pattern from ~/go/pkg/mod/cache/* to ~/go/pkg/mod/*
- Split Go cache into separate build and module entries

Fixes #521
This commit is contained in:
Noah Qin
2026-03-03 15:57:45 +08:00
committed by GitHub
parent 66ba1889c6
commit 5d4c304797
2 changed files with 46 additions and 4 deletions

View File

@@ -117,8 +117,50 @@ clean_dev_python() {
# Go build/module caches.
clean_dev_go() {
if command -v go > /dev/null 2>&1; then
clean_tool_cache "Go cache" bash -c 'go clean -modcache > /dev/null 2>&1 || true; go clean -cache > /dev/null 2>&1 || true'
note_activity
# Get Go cache paths
local go_build_cache
local go_mod_cache
go_build_cache=$(go env GOCACHE 2> /dev/null || echo "$HOME/Library/Caches/go-build")
go_mod_cache=$(go env GOMODCACHE 2> /dev/null || echo "$HOME/go/pkg/mod")
# Check if Go caches are whitelisted
local build_protected=false
local mod_protected=false
if is_path_whitelisted "$go_build_cache"; then
build_protected=true
fi
if is_path_whitelisted "$go_mod_cache"; then
mod_protected=true
fi
# Only clean if not protected by whitelist
if [[ "$build_protected" == "true" && "$mod_protected" == "true" ]]; then
if [[ "$DRY_RUN" == "true" ]]; then
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Go cache · would skip (whitelist)"
else
echo -e " ${BLUE}${ICON_SKIP}${NC} Go cache · protected by whitelist"
fi
elif [[ "$build_protected" == "true" ]]; then
# Only clean module cache
clean_tool_cache "Go module cache" bash -c 'go clean -modcache > /dev/null 2>&1 || true'
if [[ "$DRY_RUN" != "true" ]]; then
echo -e " ${BLUE}${ICON_SKIP}${NC} Go build cache · protected by whitelist"
fi
note_activity
elif [[ "$mod_protected" == "true" ]]; then
# Only clean build cache
clean_tool_cache "Go build cache" bash -c 'go clean -cache > /dev/null 2>&1 || true'
if [[ "$DRY_RUN" != "true" ]]; then
echo -e " ${BLUE}${ICON_SKIP}${NC} Go module cache · protected by whitelist"
fi
note_activity
else
# Clean both caches
clean_tool_cache "Go cache" bash -c 'go clean -modcache > /dev/null 2>&1 || true; go clean -cache > /dev/null 2>&1 || true'
note_activity
fi
fi
}
# Rust/cargo caches.

View File

@@ -94,8 +94,8 @@ VS Code extension and update cache|$HOME/Library/Application Support/Code/Cached
VS Code system cache (Cursor, VSCodium)|$HOME/Library/Caches/com.microsoft.VSCode/*|ide_cache
Cursor editor cache|$HOME/Library/Caches/com.todesktop.230313mzl4w4u92/*|ide_cache
Bazel build cache|$HOME/.cache/bazel/*|compiler_cache
Go build cache and module cache|$HOME/Library/Caches/go-build/*|compiler_cache
Go module cache|$HOME/go/pkg/mod/cache/*|compiler_cache
Go build cache|$HOME/Library/Caches/go-build/*|compiler_cache
Go module cache|$HOME/go/pkg/mod/*|compiler_cache
Rust Cargo registry cache|$HOME/.cargo/registry/cache/*|compiler_cache
Rust documentation cache|$HOME/.rustup/toolchains/*/share/doc/*|compiler_cache
Rustup toolchain downloads|$HOME/.rustup/downloads/*|compiler_cache