From 043b85f84df4470252e6424de17e4bd255f52035 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Thu, 7 Mar 2013 19:55:18 -0600 Subject: [PATCH] Move force-delete to t/lib.sh from test.sh and test-meta.sh; improve. Only call chattr and setfacl on Linux for now. Test that each item is actually gone. Signed-off-by: Rob Browning --- t/lib.sh | 19 +++++++++++++++++++ t/test-meta.sh | 16 +--------------- t/test.sh | 13 ++----------- 3 files changed, 22 insertions(+), 26 deletions(-) create mode 100644 t/lib.sh diff --git a/t/lib.sh b/t/lib.sh new file mode 100644 index 0000000..e8e5268 --- /dev/null +++ b/t/lib.sh @@ -0,0 +1,19 @@ + +force-delete() +{ + # Try *hard* to delete $@. Among other things, some systems have + # r-xr-xr-x for root and other system dirs. + rm -rf "$@" # Maybe we'll get lucky. + for f in "$@"; do + test -e "$@" || continue + chmod -R u+w "$@" + if [[ $(uname) =~ Linux ]]; then + chattr -fR = "$@" + setfacl -Rb "$@" + fi + rm -r "$@" + if test -e "$@"; then + return 1 + fi + done +} diff --git a/t/test-meta.sh b/t/test-meta.sh index 3a1da1d..1354505 100755 --- a/t/test-meta.sh +++ b/t/test-meta.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash . wvtest.sh +. t/lib.sh TOP="$(pwd)" export BUP_DIR="$TOP/buptest.tmp" @@ -34,21 +35,6 @@ actually-root() test "$(whoami)" == root -a -z "$FAKEROOTKEY" } -force-delete() -{ - if ! actually-root; then - rm -rf "$@" - else - # Go to greater lengths to deal with any test detritus. - for f in "$@"; do - test -e "$@" || continue - chattr -fR = "$@" || true - setfacl -Rb "$@" - rm -r "$@" - done - fi -} - test-src-create-extract() { # Test bup meta create/extract for ./src -> ./src-restore. diff --git a/t/test.sh b/t/test.sh index 8c81452..4211658 100755 --- a/t/test.sh +++ b/t/test.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash . wvtest.sh +. t/lib.sh + #set -e TOP="$(/bin/pwd)" @@ -10,17 +12,6 @@ bup() "$TOP/bup" "$@" } -force-delete() -{ - chmod -R u+w "$@" - for f in "$@"; do - test -e "$@" || continue - chattr -fR = "$@" || true - setfacl -Rb "$@" - rm -r "$@" - done -} - WVSTART "init" #set -x -- 2.39.2