Skip to content

Commit 7bb5836

Browse files
committed
fix(clean): make Docker cleanup safe by default
1 parent b8f2a3f commit 7bb5836

File tree

3 files changed

+23
-63
lines changed

3 files changed

+23
-63
lines changed

lib/clean/dev.sh

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -253,38 +253,10 @@ check_rust_toolchains() {
253253
# Docker caches (guarded by daemon check).
254254
clean_dev_docker() {
255255
if command -v docker > /dev/null 2>&1; then
256-
if [[ "$DRY_RUN" != "true" ]]; then
257-
start_section_spinner "Checking Docker daemon..."
258-
local docker_running=false
259-
if run_with_timeout 3 docker info > /dev/null 2>&1; then
260-
docker_running=true
261-
fi
262-
stop_section_spinner
263-
if [[ "$docker_running" == "true" ]]; then
264-
# Remove unused images, stopped containers, unused networks, and
265-
# anonymous volumes in one pass. This maps better to the large
266-
# reclaimable "docker system df" buckets users typically see.
267-
# Skip if Docker paths are whitelisted: docker system prune operates
268-
# through the daemon API and bypasses filesystem-level whitelist checks.
269-
if is_path_whitelisted "$HOME/.docker" ||
270-
is_path_whitelisted "$HOME/Library/Containers/com.docker.docker" ||
271-
is_path_whitelisted "$HOME/Library/Group Containers/group.com.docker"; then
272-
echo -e " ${GRAY}${ICON_WARNING}${NC} Docker unused data · skipped (whitelisted)"
273-
echo -e " ${GRAY}${ICON_REVIEW}${NC} ${GRAY}Review: mo clean --whitelist, protect Docker Desktop data to disable this prune${NC}"
274-
debug_log "Docker cleanup skipped: Docker paths found in whitelist"
275-
else
276-
clean_tool_cache "Docker unused data" docker system prune -af --volumes
277-
fi
278-
else
279-
echo -e " ${GRAY}${ICON_WARNING}${NC} Docker unused data · skipped (daemon not running)"
280-
note_activity
281-
debug_log "Docker daemon not running, skipping Docker cache cleanup"
282-
fi
283-
else
284-
note_activity
285-
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Docker unused data · would clean"
286-
echo -e " ${GRAY}${ICON_REVIEW}${NC} ${GRAY}Review: mo clean --whitelist, protect Docker Desktop data to disable this prune${NC}"
287-
fi
256+
note_activity
257+
echo -e " ${GRAY}${ICON_WARNING}${NC} Docker unused data · skipped by default"
258+
echo -e " ${GRAY}${ICON_REVIEW}${NC} ${GRAY}Review: docker system df${NC}"
259+
debug_log "Docker daemon-managed cleanup skipped by default"
288260
fi
289261
safe_clean ~/.docker/buildx/cache/* "Docker BuildX cache"
290262
}

lib/manage/whitelist.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Firefox browser cache|$HOME/Library/Caches/Firefox/*|browser_cache
142142
Brave browser cache|$HOME/Library/Caches/BraveSoftware/Brave-Browser/*|browser_cache
143143
Surge proxy cache|$HOME/Library/Caches/com.nssurge.surge-mac/*|network_tools
144144
Surge configuration and data|$HOME/Library/Application Support/com.nssurge.surge-mac/*|network_tools
145-
Docker Desktop data (skip Docker unused data prune)|$HOME/Library/Containers/com.docker.docker/Data/*|container_cache
145+
Docker BuildX cache|$HOME/.docker/buildx/cache/*|container_cache
146146
Podman container cache|$HOME/.local/share/containers/cache/*|container_cache
147147
Font cache|$HOME/Library/Caches/com.apple.FontRegistry/*|system_cache
148148
Spotlight metadata cache|$HOME/Library/Caches/com.apple.spotlight/*|system_cache

tests/clean_dev_caches.bats

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -287,61 +287,51 @@ EOF
287287
[[ "$output" != *"Orphaned bun cache"* ]]
288288
}
289289

290-
@test "clean_dev_docker skips when daemon not running" {
290+
@test "clean_dev_docker skips daemon-managed cleanup by default" {
291291
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=false bash --noprofile --norc <<'EOF'
292292
set -euo pipefail
293293
source "$PROJECT_ROOT/lib/core/common.sh"
294294
source "$PROJECT_ROOT/lib/clean/dev.sh"
295-
start_section_spinner() { :; }
296-
stop_section_spinner() { :; }
297-
run_with_timeout() { return 1; }
295+
clean_tool_cache() { echo "$1|$*"; }
298296
safe_clean() { echo "$2"; }
297+
note_activity() { :; }
299298
debug_log() { :; }
300-
docker() { return 1; }
299+
docker() { echo "docker called"; return 0; }
301300
export -f docker
302301
clean_dev_docker
303302
EOF
304303

305304
[ "$status" -eq 0 ]
306-
[[ "$output" == *"Docker unused data · skipped (daemon not running)"* ]]
305+
[[ "$output" == *"Docker unused data · skipped by default"* ]]
306+
[[ "$output" == *"Review: docker system df"* ]]
307307
[[ "$output" == *"Docker BuildX cache"* ]]
308-
[[ "$output" != *"Docker unused data|Docker unused data docker system prune -af --volumes"* ]]
308+
[[ "$output" != *"docker called"* ]]
309+
[[ "$output" != *"docker system prune"* ]]
309310
}
310311

311-
@test "clean_dev_docker prunes unused docker data when daemon is running" {
312+
@test "clean_dev_docker keeps BuildX cache cleanup" {
312313
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=false bash --noprofile --norc <<'EOF'
313314
set -euo pipefail
314315
source "$PROJECT_ROOT/lib/core/common.sh"
315316
source "$PROJECT_ROOT/lib/clean/dev.sh"
316-
start_section_spinner() { :; }
317-
stop_section_spinner() { :; }
318-
run_with_timeout() { shift; "$@"; }
319317
clean_tool_cache() { echo "$1|$*"; }
320-
safe_clean() { :; }
318+
safe_clean() { echo "$2|$1"; }
321319
note_activity() { :; }
322320
debug_log() { :; }
323-
docker() {
324-
if [[ "$1" == "info" ]]; then
325-
return 0
326-
fi
327-
return 0
328-
}
321+
docker() { return 0; }
329322
export -f docker
330323
clean_dev_docker
331324
EOF
332325

333326
[ "$status" -eq 0 ]
334-
[[ "$output" == *"Docker unused data|Docker unused data docker system prune -af --volumes"* ]]
327+
[[ "$output" == *"Docker BuildX cache|$HOME/.docker/buildx/cache/*"* ]]
335328
}
336329

337-
@test "clean_dev_docker skips prune when Docker paths are whitelisted" {
330+
@test "clean_dev_docker no longer depends on whitelist to avoid prune" {
338331
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" DRY_RUN=false bash --noprofile --norc <<'EOF'
339332
set -euo pipefail
340333
source "$PROJECT_ROOT/lib/core/common.sh"
341334
source "$PROJECT_ROOT/lib/clean/dev.sh"
342-
start_section_spinner() { :; }
343-
stop_section_spinner() { :; }
344-
run_with_timeout() { shift; "$@"; }
345335
clean_tool_cache() { echo "$1|$*"; }
346336
safe_clean() { :; }
347337
note_activity() { :; }
@@ -351,18 +341,16 @@ is_path_whitelisted() {
351341
return 1
352342
}
353343
export -f is_path_whitelisted
354-
docker() {
355-
if [[ "$1" == "info" ]]; then
356-
return 0
357-
fi
358-
return 0
359-
}
344+
docker() { echo "docker called"; return 0; }
360345
export -f docker
361346
clean_dev_docker
362347
EOF
363348

364349
[ "$status" -eq 0 ]
365-
[[ "$output" == *"Docker unused data · skipped (whitelisted)"* ]]
350+
[[ "$output" == *"Docker unused data · skipped by default"* ]]
351+
[[ "$output" != *"whitelisted"* ]]
352+
[[ "$output" != *"mo clean --whitelist"* ]]
353+
[[ "$output" != *"docker called"* ]]
366354
[[ "$output" != *"docker system prune"* ]]
367355
}
368356

0 commit comments

Comments
 (0)