]> arthur.barton.de Git - bup.git/blob - t/compare-trees
Don't pass --tmpdir to mktemp or expect it to have a default template.
[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 "hc" 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     rsync_opts="$rsync_opts -AX"
52 else
53     echo "Not comparing xattrs/acls (unsupported by available rsync)." 1>&2
54 fi
55
56 rsync $rsync_opts "$src" "$dest" > "${tmpfile}"
57
58 if test $(wc -l < "${tmpfile}") != 0; then
59     echo "Differences between $src and $dest"
60     cat "${tmpfile}"
61     exit 1
62 fi
63
64 exit 0