From 948ed3f1fab2a5e02cd8f4f12df2475300e4ad07 Mon Sep 17 00:00:00 2001 From: Michael Greenberg Date: Tue, 19 Nov 2024 12:33:33 -0500 Subject: [PATCH] capture absolute path of sandbox dir, cleanup --- test/tempfiles.sh | 12 ++++++++---- try | 7 ++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/test/tempfiles.sh b/test/tempfiles.sh index 66daae6..25e6adb 100755 --- a/test/tempfiles.sh +++ b/test/tempfiles.sh @@ -4,6 +4,9 @@ TRY_TOP="${TRY_TOP:-$(git rev-parse --show-toplevel --show-superproject-working-tree 2>/dev/null || echo "${0%/*}")}" TRY="$TRY_TOP/try" +workdir="$(mktemp -d)" +cd "$workdir" || exit 1 + initial_count="$(ls "${TMPDIR-/tmp}" | grep -e "^.*\.try-[0-9]*$" | wc -l)" sandbox=$($TRY -n "touch $HOME/foo") @@ -16,11 +19,12 @@ post_count="$(ls "${TMPDIR-/tmp}" | grep -e "^.*\.try-[0-9]*$" | wc -l)" [ -f "$sandbox/upperdir$HOME/foo" ] || exit 4 # deliberately not the pattern of try sandboxes -sandbox="$(mktemp -d --suffix "custom-XXXXXX")" -$TRY -D "$sandbox" "touch $HOME/bar" || exit 5 +sandbox=local +mkdir "$sandbox" || exit 5 +$TRY -D "$sandbox" "touch $HOME/bar" || exit 6 final_count="$(ls "${TMPDIR-/tmp}" | grep -e "^.*\.try-[0-9]*$" | wc -l)" # no new tempfiles! -[ "$post_count" -eq "$final_count" ] || exit 6 -[ -f "$sandbox/upperdir$HOME/bar" ] || exit 7 +[ "$post_count" -eq "$final_count" ] || exit 7 +[ -f "$sandbox/upperdir$HOME/bar" ] || exit 8 diff --git a/try b/try index 7bae1c6..3f8e059 100755 --- a/try +++ b/try @@ -34,7 +34,12 @@ try() { if [ "$SANDBOX_DIR" ] then ## If the name of a sandbox is given then we need to exit prematurely if its directory doesn't exist - ! [ -d "$SANDBOX_DIR" ] && { error "could not find sandbox directory $SANDBOX_DIR" 2; } + [ -d "$SANDBOX_DIR" ] || error "could not find sandbox directory $SANDBOX_DIR" 2 + # Force absolute path + SANDBOX_DIR="$(cd "$SANDBOX_DIR" && pwd)" + + # shellcheck disable=SC2181 + [ "$?" -eq 0 ] || error "could not find sandbox directory $SANDBOX_DIR (could not cd in)" 2 else ## Create a new sandbox if one was not given SANDBOX_DIR="$(mktemp -d --suffix ".try-$EXECID")"