From: Rob Browning Date: Tue, 29 Oct 2013 01:23:38 +0000 (-0500) Subject: Make force-delete more flexible, and more likely to succeed. X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=ad9bf3df983eacb7fe12a8270f6ff2abc2f77bf1;p=packages%2Fb%2Fbup.git Make force-delete more flexible, and more likely to succeed. Thanks to Alexander Barton for helping track down the correct chattr invocation. Signed-off-by: Rob Browning --- diff --git a/t/lib.sh b/t/lib.sh index a2e94de..4640379 100644 --- a/t/lib.sh +++ b/t/lib.sh @@ -2,21 +2,28 @@ force-delete() { + local rc=0 # 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 "$@" + test -e "$f" || continue + if test "$(type -p setfacl)"; then + setfacl -Rb "$f" fi - rm -r "$@" - if test -e "$@"; then - return 1 + if test "$(type -p chattr)"; then + chattr -R -aisu "$f" + fi + chmod -R u+rwX "$f" + rm -r "$f" + if test -e "$f"; then + rc=1 + find "$f" -ls + lsattr -aR "$f" + getfacl -R "$f" fi done + return $rc } realpath()