8 top="$(WVPASS pwd)" || exit $?
9 tmpdir="$(WVPASS wvmktempdir)" || exit $?
10 export BUP_DIR="$tmpdir/bup"
12 bup() { "$top/bup" "$@"; }
14 validate-local-and-remote-restore()
16 local src="$1" dest="$2" cmp_src="$3" cmp_dest="$4"
18 WVPASS bup restore -C "$dest" "$src"
19 WVPASS "$top/dev/compare-trees" "$cmp_src" "$cmp_dest"
21 WVPASS bup restore -r ":$BUP_DIR" -C "$dest" "$src"
22 WVPASS "$top/dev/compare-trees" "$cmp_src" "$cmp_dest"
30 # Be independent of git defaults or a configured defaultBranch
31 git --git-dir "$BUP_DIR" symbolic-ref HEAD refs/heads/main
33 WVPASS force-delete $D
36 WVPASS bup random 128k >$D/b
37 WVPASS mkdir $D/d $D/d/e
38 WVPASS bup random 512 >$D/f
46 WVPASS force-delete buprestore.tmp
47 WVFAIL bup restore boink
48 WVPASS touch "$tmpdir/$D/$D"
49 WVPASS bup index -u "$tmpdir/$D"
50 WVPASS bup save -n main /
51 WVPASS bup restore -C buprestore.tmp "/main/latest/$tmpdir/$D"
52 WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
53 WVPASS force-delete buprestore.tmp
54 WVPASS bup restore -C buprestore.tmp "/main/latest/$tmpdir/$D/"
55 WVPASS touch $D/non-existent-file buprestore.tmp/non-existent-file # else diff fails
56 WVPASS diff -ur $D/ buprestore.tmp/
57 WVPASS force-delete buprestore.tmp
58 WVPASS echo -n "" | WVPASS bup split -n split_empty_string.tmp
59 WVPASS bup restore -C buprestore.tmp split_empty_string.tmp/latest/
60 WVPASSEQ "$(cat buprestore.tmp/data)" ""
65 WVPASS force-delete $tmp
67 export BUP_DIR="$(pwd)/$tmp/bup"
68 WVPASS WVPASS bup init
69 WVPASS mkdir -p $tmp/src/x/y/z
70 WVPASS bup random 8k > $tmp/src/x/y/random-1
71 WVPASS bup random 8k > $tmp/src/x/y/z/random-2
72 WVPASS bup index -u $tmp/src
73 WVPASS bup save --strip -n foo $tmp/src
75 WVSTART "restore /foo/latest"
76 validate-local-and-remote-restore \
77 /foo/latest "$tmp/restore" \
78 "$tmp/src/" "$tmp/restore/latest/"
80 WVSTART "restore /foo/latest/."
81 WVPASS force-delete "$tmp/restore"
82 validate-local-and-remote-restore \
83 /foo/latest/. "$tmp"/restore \
84 "$tmp"/src/ "$tmp"/restore
86 WVSTART "restore /foo/latest/x"
87 WVPASS force-delete "$tmp/restore"
88 validate-local-and-remote-restore \
89 /foo/latest/x "$tmp"/restore \
90 "$tmp"/src/x/ "$tmp"/restore/x/
92 WVSTART "restore /foo/latest/x/"
93 WVPASS force-delete "$tmp/restore"
94 WVPASS bup restore -C "$tmp"/restore /foo/latest/x/
95 for x in "$tmp"/src/x/*; do
96 WVPASS "$top/dev/compare-trees" "$x/" "$tmp/restore/$(basename $x)"
98 WVPASS force-delete "$tmp/restore"
99 WVPASS bup restore -r ":$BUP_DIR" -C "$tmp"/restore /foo/latest/x/
100 for x in "$tmp"/src/x/*; do
101 WVPASS "$top/dev/compare-trees" "$x/" "$tmp/restore/$(basename $x)"
104 WVSTART "restore /foo/latest/x/."
105 WVPASS force-delete "$tmp/restore"
106 validate-local-and-remote-restore \
107 /foo/latest/x/. "$tmp"/restore \
108 "$tmp"/src/x/ "$tmp"/restore/
112 WVSTART "save (no index)"
114 tmp=save-no-index.tmp
115 WVPASS force-delete $tmp
117 export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
119 WVFAIL bup save -n nothing /
124 WVSTART "save disjoint top-level directories"
126 # Resolve any symlinks involving the top top-level dirs.
127 real_pwd="$(WVPASS resolve-parent .)" || exit $?
128 real_tmp="$(WVPASS resolve-parent /tmp/.)" || exit $?
129 pwd_top="$(echo $real_pwd | WVPASS awk -F "/" '{print $2}')" || exit $?
130 tmp_top="$(echo $real_tmp | WVPASS awk -F "/" '{print $2}')" || exit $?
132 if [ "$pwd_top" = "$tmp_top" ]; then
133 echo "(running from within /$tmp_top; skipping test)" 1>&2
134 exit 0 # FIXME: allow intermixed WVSKIPs
137 WVPASS force-delete $D
140 tmpdir2="$(WVPASS mktemp -d $real_tmp/bup-test-XXXXXXX)" || exit $?
141 cleanup() { WVPASS rm -r "$tmpdir2"; }
142 WVPASS trap cleanup EXIT
143 WVPASS date > "$tmpdir2/2"
145 export BUP_DIR="$tmpdir/bup"
146 WVPASS test -d "$BUP_DIR" && WVPASS rm -r "$BUP_DIR"
149 WVPASS bup index -vu $(pwd)/$D/x "$tmpdir2"
150 WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir2"
152 # For now, assume that "ls -a" and "sort" use the same order.
153 actual="$(WVPASS bup ls -AF src/latest)" || exit $?
154 expected="$(echo -e "$pwd_top/\n$tmp_top/" | WVPASS sort)" || exit $?
155 WVPASSEQ "$actual" "$expected"
160 WVPASS rm -rf "$tmpdir"