]> arthur.barton.de Git - bup.git/blob - t/compare-trees
t/compare-trees: don't check ACLs on Cygwin (no support).
[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 if rsync --version | grep -q xattrs; then
51     if [[ $(uname) =~ CYGWIN ]]; then
52         # bup doesn't support ACLs on Cygwin yet.
53         rsync_opts="$rsync_opts -X"
54     else
55         rsync_opts="$rsync_opts -AX"
56     fi
57 else
58     echo "Not comparing xattrs/acls (unsupported by available rsync)." 1>&2
59 fi
60
61 rsync $rsync_opts "$src" "$dest" > "${tmpfile}"
62
63 if test $(wc -l < "${tmpfile}") != 0; then
64     echo "Differences between $src and $dest"
65     cat "${tmpfile}"
66     exit 1
67 fi
68
69 exit 0