X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=t%2Flib.sh;h=4d67341e5330c7e725ebb50915a7128a5e54c173;hb=ea0cb087050dc86bae886c0b2605b83aa819b7d3;hp=e7e2ce8d71458d31e2771e5c7282ed0695d23d73;hpb=2f899b28de98a70773f8034c64b25d37c6b9543e;p=bup.git diff --git a/t/lib.sh b/t/lib.sh index e7e2ce8..4d67341 100644 --- a/t/lib.sh +++ b/t/lib.sh @@ -1,30 +1,58 @@ -# Assumes shell is Bash. +# Assumes shell is Bash, and pipefail is set. + +bup_t_lib_script_home=$(cd "$(dirname $0)" && pwd) || exit $? + +bup-python() +{ + "$bup_t_lib_script_home/../cmd/bup-python" "$@" +} 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 + "$bup_t_lib_script_home/force-delete" "$@" } -realpath() -( - set -e; - test "$#" -eq 1 - script_home=$(cd "$(dirname $0)" && pwd) +resolve-parent() +{ + test "$#" -eq 1 || return $? echo "$1" | \ - PYTHONPATH="${script_home}/../lib" python -c \ - "import sys, bup.helpers; print bup.helpers.realpath(sys.stdin.readline())" + PYTHONPATH="$bup_t_lib_script_home/../lib" bup-python -c \ + "import sys, bup.helpers; print(bup.helpers.resolve_parent(sys.stdin.readline()))" \ + || return $? +} + +current-filesystem() +{ + local kernel="$(uname -s)" || return $? + case "$kernel" in + NetBSD) + df -G . | sed -En 's/.* ([^ ]*) fstype.*/\1/p' + ;; + SunOS) + df -g . | sed -En 's/.* ([^ ]*) fstype.*/\1/p' + ;; + *) + df -T . | awk 'END{print $2}' + esac +} + +path-filesystems() +( + # Return filesystem for each dir from $1 to /. + # Perhaps for /foo/bar, "ext4\next4\nbtrfs\n". + test "$#" -eq 1 || exit $? + cd "$1" || exit $? + current-filesystem || exit $? + dir="$(pwd)" || exit $? + while test "$dir" != /; do + cd .. || exit $? + dir="$(pwd)" || exit $? + current-filesystem || exit $? + done + exit 0 ) + +escape-erx() +{ + sed 's/[][\.|$(){?+*^]/\\&/g' <<< "$*" +}