Skip to content

Commit

Permalink
capture absolute path of sandbox dir, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mgree committed Nov 19, 2024
1 parent 14696fd commit 948ed3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 8 additions & 4 deletions test/tempfiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
7 changes: 6 additions & 1 deletion try
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand Down

0 comments on commit 948ed3f

Please sign in to comment.