Skip to content

Commit 62d21d8

Browse files
committed
fix: show only running containers in force-delete prompt
Previously, when deleting multiple containers with `distrobox-rm`, if any container was running, the prompt incorrectly showed the entire container list instead of just the running containers. This fix: - Collects all running container names first - Shows only running containers in the force-delete prompt - Asks once for all running containers (preserving original behavior) - If user refuses, continues without force flag (running containers will fail) - Exits on invalid input instead of continuing with deletion Signed-off-by: xz-dev <xiangzhedev@gmail.com>
1 parent 2995df5 commit 62d21d8

1 file changed

Lines changed: 21 additions & 13 deletions

File tree

distrobox-rm

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -418,32 +418,40 @@ else
418418
response="yes"
419419
fi
420420

421+
# Collect running containers first
422+
running_containers=""
421423
for container in ${container_name_list}; do
422424
if [ "$(${container_manager} inspect --type container --format '{{.State.Status}}' "${container}")" = "running" ]; then
423-
if [ "${non_interactive}" -eq 0 ] && [ "${force}" -eq 0 ]; then
424-
printf "Container %s running, do you want to force delete them? [Y/n]: " "${container_name_list}"
425-
read -r response_force
426-
response_force="${response_force:-"Y"}"
427-
else
428-
response_force="yes"
429-
fi
425+
running_containers="${running_containers} ${container}"
426+
fi
427+
done
428+
429+
# If there are running containers, ask once for all of them
430+
if [ -n "${running_containers}" ]; then
431+
if [ "${non_interactive}" -eq 0 ] && [ "${force}" -eq 0 ]; then
432+
printf "Containers%s are running, do you want to force delete them? [Y/n]: " "${running_containers}"
433+
read -r response_force
434+
response_force="${response_force:-"Y"}"
435+
else
436+
response_force="yes"
430437
fi
431438

432439
# Accept only y,Y,Yes,yes,n,N,No,no.
433-
case "${response_force:-"N"}" in
440+
case "${response_force}" in
434441
y | Y | Yes | yes | YES)
435442
force=1
436443
force_flag="--force"
437-
break
438444
;;
439-
n | N | No | no | NO) ;;
440-
441-
*) # Default case: If no more options then break out of the loop.
445+
n | N | No | no | NO)
446+
# Continue without force flag - running containers will fail to delete
447+
;;
448+
*)
442449
printf >&2 "Invalid input.\n"
443450
printf >&2 "The available choices are: y,Y,Yes,yes,YES or n,N,No,no,NO.\nExiting.\n"
451+
exit 1
444452
;;
445453
esac
446-
done
454+
fi
447455

448456
# Accept only y,Y,Yes,yes,n,N,No,no.
449457
case "${response}" in

0 commit comments

Comments
 (0)