diff --git a/lib/clean/dev.sh b/lib/clean/dev.sh index 90b9f3a..d2908c3 100644 --- a/lib/clean/dev.sh +++ b/lib/clean/dev.sh @@ -116,52 +116,35 @@ clean_dev_python() { } # Go build/module caches. clean_dev_go() { - if command -v go > /dev/null 2>&1; then - # 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") + command -v go > /dev/null 2>&1 || return 0 - # Check if Go caches are whitelisted - local build_protected=false - local mod_protected=false + local go_build_cache 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") - if is_path_whitelisted "$go_build_cache"; then - build_protected=true - fi + local build_protected=false mod_protected=false + is_path_whitelisted "$go_build_cache" && build_protected=true + is_path_whitelisted "$go_mod_cache" && mod_protected=true - 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 + 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 - # 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 + echo -e " ${GREEN}${ICON_SUCCESS}${NC} Go cache · skipped (whitelist)" fi + return 0 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. clean_dev_rust() {