From 96b230ecf2feac2d1bb68de170a8be48911e6648 Mon Sep 17 00:00:00 2001 From: tstromberg Date: Wed, 9 Oct 2019 15:37:12 -0700 Subject: [PATCH] Fix wildcard deletion --- hack/jenkins/common.sh | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/hack/jenkins/common.sh b/hack/jenkins/common.sh index 99772b8f90..14b88c9a48 100755 --- a/hack/jenkins/common.sh +++ b/hack/jenkins/common.sh @@ -91,28 +91,34 @@ if [[ "${procs}" != "" ]]; then kill -9 ${procs} || true fi +# Quickly notice misconfigured test roots +mkdir -p "${TEST_ROOT}" + # Cleanup stale test outputs. echo "" echo ">> Cleaning up after previous test runs ..." - -for stale_dir in ${TEST_ROOT}/*; do - echo "* Cleaning stale test root: ${stale_dir}" - - for tunnel in $(find ${stale_dir} -name tunnels.json -type f); do +for entry in $(ls ${TEST_ROOT}); do + echo "* Cleaning stale test path: ${entry}" + for tunnel in $(find ${entry} -name tunnels.json -type f); do env MINIKUBE_HOME="$(dirname ${tunnel})" ${MINIKUBE_BIN} tunnel --cleanup || true done - for home in $(find ${stale_dir} -name .minikube -type d); do - env MINIKUBE_HOME="$(dirname ${home})" ${MINIKUBE_BIN} delete || true - sudo rm -Rf "${home}" + for home in $(find ${entry} -name .minikube -type d); do + env MINIKUBE_HOME="$(dirname ${home})" ${MINIKUBE_BIN} delete || true + sudo rm -Rf "${home}" done - for kconfig in $(find ${stale_dir} -name kubeconfig -type f); do + for kconfig in $(find ${entry} -name kubeconfig -type f); do sudo rm -f "${kconfig}" done - rm -f "${stale_dir}/*" || true - rmdir "${stale_dir}" || ls "${stale_dir}" + # Be very specific to avoid accidentally deleting other items, like wildcards or devices + if [[ -d "${entry}" ]]; then + rm -Rf "${entry}" || true + elif [[ -f "${entry}" ]]; then + rm -f "${entry}" || true + fi + done # sometimes tests left over zombie procs that won't exit