mirror of
https://github.com/tw93/Mole.git
synced 2026-03-24 04:20:07 +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:
@@ -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_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 go_build_cache go_mod_cache
|
||||||
local build_protected=false
|
go_build_cache=$(go env GOCACHE 2> /dev/null || echo "$HOME/Library/Caches/go-build")
|
||||||
local mod_protected=false
|
go_mod_cache=$(go env GOMODCACHE 2> /dev/null || echo "$HOME/go/pkg/mod")
|
||||||
|
|
||||||
if is_path_whitelisted "$go_build_cache"; then
|
local build_protected=false mod_protected=false
|
||||||
build_protected=true
|
is_path_whitelisted "$go_build_cache" && build_protected=true
|
||||||
fi
|
is_path_whitelisted "$go_mod_cache" && mod_protected=true
|
||||||
|
|
||||||
if is_path_whitelisted "$go_mod_cache"; then
|
if [[ "$build_protected" == "true" && "$mod_protected" == "true" ]]; then
|
||||||
mod_protected=true
|
if [[ "$DRY_RUN" == "true" ]]; then
|
||||||
fi
|
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Go cache · would skip (whitelist)"
|
||||||
|
|
||||||
# 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
|
else
|
||||||
# Clean both caches
|
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Go cache · skipped (whitelist)"
|
||||||
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
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$build_protected" != "true" && "$mod_protected" != "true" ]]; then
|
||||||
|
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
|
||||||
}
|
}
|
||||||
# Rust/cargo caches.
|
# Rust/cargo caches.
|
||||||
clean_dev_rust() {
|
clean_dev_rust() {
|
||||||
|
|||||||
Reference in New Issue
Block a user