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

refactor(clean): simplify Go cache whitelist logic

- Fix undefined ICON_SKIP, use ICON_SUCCESS instead
- Reduce code from 46 to 27 lines with early return pattern
- Consistent styling with other whitelist skip messages
This commit is contained in:
tw93
2026-03-03 16:02:23 +08:00
parent ab35f2e8f1
commit 677077818e

View File

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