Skip to content

Commit 5209fb8

Browse files
[PATCH] Implements the improvements from #198
Changes in file tests/check_pip: * Fixed cleanup for venv * improved check_license_when_given_req
1 parent e81581f commit 5209fb8

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

tests/check_pip

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ umask 137
102102
export LC_CTYPE="${LC_CTYPE:-en_US.UTF-8}"
103103
# set remaining variables
104104
LOCK_FILE="${TMPDIR:-/tmp}/org.pak.multicast.pip-check-shell"
105+
# Global variable to track temporary directories
106+
TEMP_DIRS=""
107+
# Global variable to track initial directories
108+
readonly PRE_OLDPWD="${OLDPWD:-${PWD:-$(pwd)}}"
109+
readonly PRE_PWD="${PWD:-$(pwd)}"
105110

106111
# Function to check if a command exists.
107112

@@ -153,8 +158,19 @@ EXIT_CODE=1
153158
# Results:
154159
# returns -- once cleanup has been done on a best-effort case.
155160
function cleanup() {
161+
for dir in ${TEMP_DIRS}; do
162+
if [[ ( -n "${dir}" ) ]] && [[ ( -d "${dir}" ) ]]; then
163+
rm -rfd "${dir}" 2>/dev/null || : ;
164+
fi
165+
done
156166
rm -f "${LOCK_FILE}" 2>/dev/null || : ; wait ;
167+
# best effort to restore starting location
168+
cd "${PRE_PWD}" && cd "${PRE_OLDPWD}" 2>/dev/null || : ;
169+
cd "${PRE_PWD}" 2>/dev/null || : ;
157170
# unset when done
171+
unset TEMP_DIRS 2>/dev/null || : ;
172+
unset PRE_OLDPWD 2>/dev/null || : ;
173+
unset PRE_PWD 2>/dev/null || : ;
158174
unset LOCK_FILE 2>/dev/null || : ;
159175
hash -d shlock 2>/dev/null || : ;
160176
}
@@ -172,7 +188,7 @@ function handle_signals() {
172188
trap 'cleanup 2>/dev/null || rm -f ${LOCK_FILE} 2>/dev/null || true ; wait ; exit ${EXIT_CODE} ;' EXIT || EXIT_CODE=1
173189
else
174190
# shellcheck disable=SC2046
175-
printf "\t%s\n" "Check Setup Scripts Tests Coverage already in progress by "$(head "${LOCK_FILE}") >&2 ;
191+
printf "\t%s\n" "Check PIP Configuration Tests already in progress by "$(head "${LOCK_FILE}") >&2 ;
176192
exit 126 ;
177193
fi
178194
}
@@ -241,8 +257,8 @@ function check_license_when_given_req() {
241257
umask 007
242258
printf "::debug::%s\n" "need venv ..." ;
243259
# Create a temporary directory for the virtual environment
244-
temp_dir=$(mktemp -d)
245-
260+
local temp_dir=$(mktemp -d)
261+
TEMP_DIRS="${TEMP_DIRS} ${temp_dir}" ;
246262
# Enter the temporary directory
247263
cd "${temp_dir}"
248264

0 commit comments

Comments
 (0)