]> arthur.barton.de Git - bup.git/blob - t/compare-trees
t/compare-trees: check rsync capability support correctly.
[bup.git] / t / compare-trees
1 #!/usr/bin/env bash
2
3 # Test that src and dest trees are as identical as bup is capable of
4 # making them.  For now, use rsync -niaHAX ...
5
6 set -e
7 set -o pipefail
8
9 usage() {
10 cat <<EOF
11 Usage: compare-trees [-h] [-c] [-x] SOURCE DEST
12 OPTIONS:
13   -h
14     Display help
15   -c
16     Check file content (default)
17   -x
18     Don't check file content (rely on size/timestamps, etc.)
19 EOF
20 }
21
22 verify_content=" --checksum"
23
24 while getopts "hcx" OPTION
25 do
26     case "$OPTION" in
27         h) usage; exit 0;;
28         c) verify_content=" --checksum";;
29         x) verify_content="";;
30         ?) usage 1>&2; exit 1;;
31     esac
32 done
33
34 shift $(($OPTIND - 1))
35
36 if ! test $# -eq 2
37 then
38     usage 1>&2
39     exit 1
40 fi
41
42 src="$1"
43 dest="$2"
44
45 tmpfile="$(mktemp /tmp/bup-test-XXXXXXX)"
46 trap "rm -rf '${tmpfile}'" EXIT
47
48 rsync_opts="-niaH$verify_content --delete"
49
50 rsync_version=$(rsync --version)
51 if [[ ! "$rsync_version" =~ "ACLs" ]] || [[ "$rsync_version" =~ "no ACLs" ]]; then
52     echo "Not comparing ACLs (not supported by available rsync)" 1>&2
53 else
54     case $OSTYPE in
55         cygwin|darwin)
56             echo "Not comparing ACLs (not yet supported on $OSTYPE)" 1>&2
57             ;;
58         *)
59             rsync_opts="$rsync_opts -A"
60             ;;
61     esac
62 fi
63
64 if [[ ! "$rsync_version" =~ "xattrs" ]] || [[ "$rsync_version" =~ "no xattrs" ]]; then
65     echo "Not comparing xattrs (not supported by available rsync)" 1>&2
66 else
67     rsync_opts="$rsync_opts -X"
68 fi
69
70 rsync $rsync_opts "$src" "$dest" > "${tmpfile}"
71
72 if test $(wc -l < "${tmpfile}") != 0; then
73     echo "Differences between $src and $dest"
74     cat "${tmpfile}"
75     exit 1
76 fi
77
78 exit 0