]> arthur.barton.de Git - bup.git/blob - t/lib.sh
Add current-filesystem and path-filesystems to t/lib.sh; use to guard test.
[bup.git] / t / lib.sh
1 # Assumes shell is Bash, and pipefail is set.
2
3 force-delete()
4 {
5     local rc=0
6     # Try *hard* to delete $@.  Among other things, some systems have
7     # r-xr-xr-x for root and other system dirs.
8     rm -rf "$@" # Maybe we'll get lucky.
9     for f in "$@"; do
10         test -e "$f" || continue
11         if test "$(type -p setfacl)"; then
12             setfacl -Rb "$f"
13         fi
14         if test "$(type -p chattr)"; then
15             chattr -R -aisu "$f"
16         fi
17         chmod -R u+rwX "$f"
18         rm -r "$f"
19         if test -e "$f"; then
20             rc=1
21             find "$f" -ls
22             lsattr -aR "$f"
23             getfacl -R "$f"
24         fi
25     done
26     return $rc
27 }
28
29 realpath()
30 {
31     test "$#" -eq 1 || return $?
32     local script_home=$(cd "$(dirname $0)" && pwd)
33     echo "$1" | \
34         PYTHONPATH="${script_home}/../lib" python -c \
35         "import sys, bup.helpers; print bup.helpers.realpath(sys.stdin.readline())" \
36         || return $?
37 }
38
39 current-filesystem()
40 {
41     df -T . | awk 'END{print $2}'
42 }
43
44 path-filesystems()
45 (
46     # Return filesystem for each dir from $1 to /.
47     # Perhaps for /foo/bar, "ext4\next4\nbtrfs\n".
48     test "$#" -eq 1 || exit $?
49     cd "$1" || exit $?
50     current-filesystem || exit $?
51     dir="$(pwd)" || exit $?
52     while test "$dir" != /; do
53         cd .. || exit $?
54         dir="$(pwd)" || exit $?
55         current-filesystem || exit $?
56     done
57     exit 0
58 )