diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-10-20 13:21:41 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-10-20 13:21:41 -0400 |
commit | 55a1ad42bd172aa235015b88c092a225ec7f4862 (patch) | |
tree | ffe5cc53024ee1a8c9a7c7029671bae7852025c9 /tests/tests.sh | |
parent | 4ec966263444dfae8837cd73b980cfdb9aabd93f (diff) | |
download | bfs-55a1ad42bd172aa235015b88c092a225ec7f4862.tar.xz |
tests: Add a helper for cleaning scratch
And try to unmount things if the a test left them mounted.
Diffstat (limited to 'tests/tests.sh')
-rwxr-xr-x | tests/tests.sh | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/tests/tests.sh b/tests/tests.sh index f6fe506..3a2446b 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -270,6 +270,26 @@ if [ ! "$EXPLICIT" ]; then enabled_tests=("${enabled_tests[@]%.sh}") fi +function clean_scratch() { + if [ -e "$TMP/scratch" ]; then + # Try to unmount anything left behind + if [ "$SUDO" ] && command -v mountpoint &>/dev/null; then + for path in "$TMP"/scratch/*; do + if mountpoint -q "$path"; then + sudo umount "$path" + fi + done + fi + + # Reset any modified permissions + chmod -R +rX "$TMP/scratch" + + rm -rf "$TMP/scratch" + fi + + mkdir "$TMP/scratch" +} + # Clean up temporary directories on exit function cleanup() { # Don't force rm to deal with long paths @@ -280,9 +300,7 @@ function cleanup() { done # In case a test left anything weird in scratch/ - if [ -e "$TMP"/scratch ]; then - chmod -R +rX "$TMP"/scratch - fi + clean_scratch rm -rf "$TMP" } @@ -451,12 +469,6 @@ function make_rainbow() { } make_rainbow "$TMP/rainbow" -# Creates a scratch directory that tests can modify -function make_scratch() { - mkdir -p "$1" -} -make_scratch "$TMP/scratch" - # Close stdin so bfs doesn't think we're interactive exec </dev/null @@ -617,7 +629,7 @@ function set_acl() { } function make_xattrs() { - rm -rf scratch/* + clean_scratch $TOUCH scratch/{normal,xattr,xattr_2} ln -s xattr scratch/link |