]> arthur.barton.de Git - bup.git/blob - t/test-redundant-saves.sh
Be more careful when testing that repeated saves can produce the same tree.
[bup.git] / t / test-redundant-saves.sh
1 #!/usr/bin/env bash
2
3 # Test that running save more than once with no other changes produces
4 # the exact same tree.
5
6 # Note: we can't compare the top-level hash (i.e. the output of "save
7 # -t" because that currently pulls the metadata for unindexed parent
8 # directories directly from the filesystem, and the relevant atimes
9 # may change between runs.  So instead we extract the roots of the
10 # indexed trees for comparison via t/subtree-hash.
11
12 . ./wvtest-bup.sh
13
14 set -eo pipefail
15
16 WVSTART 'all'
17
18 top="$(pwd)"
19 tmpdir="$(wvmktempdir)"
20 export BUP_DIR="$tmpdir/bup"
21 export GIT_DIR="$BUP_DIR"
22
23 bup() { "$top/bup" "$@"; }
24
25 mkdir -p "$tmpdir/src"
26 mkdir -p "$tmpdir/src/d"
27 mkdir -p "$tmpdir/src/d/e"
28 touch "$tmpdir/src/"{f,b,a,d}
29 touch "$tmpdir/src/d/z"
30
31 WVPASS bup init
32 WVPASS bup index -u "$tmpdir/src"
33
34 declare -a indexed_top
35 IFS=/
36 indexed_top="${tmpdir##/}"
37 indexed_top=(${indexed_top%%/})
38 unset IFS
39
40 tree1=$(bup save -t "$tmpdir/src") || WVFAIL
41 indexed_tree1="$(t/subtree-hash "$tree1" "${indexed_top[@]}" src)"
42
43 WVPASSEQ "$(cd "$tmpdir/src" && bup index -m)" ""
44
45 tree2=$(bup save -t "$tmpdir/src") || WVFAIL
46 indexed_tree2="$(t/subtree-hash "$tree2" "${indexed_top[@]}" src)"
47
48 WVPASSEQ "$indexed_tree1" "$indexed_tree2"
49
50 WVPASSEQ "$(bup index -s / | grep ^D)" ""
51
52 tree3=$(bup save -t /) || WVFAIL
53 indexed_tree3="$(t/subtree-hash "$tree3" "${indexed_top[@]}")"
54
55 WVPASSEQ "$indexed_tree3" "$indexed_tree3"
56
57 rm -rf "$tmpdir"