]> arthur.barton.de Git - bup.git/blob - t/lib.sh
test-meta.sh: escape user/group expressions
[bup.git] / t / lib.sh
1 # Assumes shell is Bash, and pipefail is set.
2
3 bup_t_lib_script_home=$(cd "$(dirname $0)" && pwd)
4
5 force-delete()
6 {
7     "$bup_t_lib_script_home/force-delete" "$@"
8 }
9
10 realpath()
11 {
12     test "$#" -eq 1 || return $?
13     echo "$1" | \
14         PYTHONPATH="$bup_t_lib_script_home/../lib" python -c \
15         "import sys, bup.helpers; print bup.helpers.realpath(sys.stdin.readline())" \
16         || return $?
17 }
18
19 current-filesystem()
20 {
21     local kernel="$(uname -s)" || return $?
22     case "$kernel" in
23         NetBSD)
24             df -G . | sed -En 's/.* ([^ ]*) fstype.*/\1/p'
25             ;;
26         SunOS)
27             df -g . | sed -En 's/.* ([^ ]*) fstype.*/\1/p'
28             ;;
29         *)
30             df -T . | awk 'END{print $2}'
31     esac
32 }
33
34 path-filesystems()
35 (
36     # Return filesystem for each dir from $1 to /.
37     # Perhaps for /foo/bar, "ext4\next4\nbtrfs\n".
38     test "$#" -eq 1 || exit $?
39     cd "$1" || exit $?
40     current-filesystem || exit $?
41     dir="$(pwd)" || exit $?
42     while test "$dir" != /; do
43         cd .. || exit $?
44         dir="$(pwd)" || exit $?
45         current-filesystem || exit $?
46     done
47     exit 0
48 )
49
50 escape-erx()
51 {
52     sed 's/[][\.|$(){?+*^]/\\&/g' <<< "$*"
53 }