From da68e2eccc3c4207ddacc4c887645447579d4fd2 Mon Sep 17 00:00:00 2001 From: "Kai Qiang Wu(Kennan)" Date: Mon, 31 Aug 2015 04:14:17 +0000 Subject: [PATCH] Improve scripts with some check before kick rm command Closes-Bug: #1490387 Change-Id: I4a9476085b9c5b2cae3801e5b1954e85068f4e03 --- tools/cleanup-containers | 8 ++++++-- tools/cleanup-images | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/cleanup-containers b/tools/cleanup-containers index 7b0e8341e0..b94c5db1e3 100755 --- a/tools/cleanup-containers +++ b/tools/cleanup-containers @@ -1,3 +1,7 @@ #!/bin/bash - -docker rm $@ $(docker ps -a -q) +CONTAINERS=`docker ps -a -q` +if [[ -z "$CONTAINERS" ]]; then + echo "No containers to cleanup, exit now." + exit 0 +fi +docker rm $@ $CONTAINERS diff --git a/tools/cleanup-images b/tools/cleanup-images index c0b1db55c6..871afd1d1a 100755 --- a/tools/cleanup-images +++ b/tools/cleanup-images @@ -6,4 +6,9 @@ cd "$(dirname "$REAL_PATH")/.." . tools/validate-docker-execute -docker rmi $@ $(docker images -a -q) +IMAGES=`docker images -a -q` +if [[ -z "$IMAGES" ]]; then + echo "No images to cleanup, exit now." + exit 0 +fi +docker rmi $@ $IMAGES