]> arthur.barton.de Git - bup.git/blob - t/test-fuse.sh
5a7365ad547b63924114de340f2d4cf5527a89a4
[bup.git] / t / test-fuse.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3 . t/lib.sh || exit $?
4
5 set -o pipefail
6
7 unset BLOCKSIZE BLOCK_SIZE DF_BLOCK_SIZE
8
9 root_status="$(t/root-status)" || exit $?
10
11 if ! bup-python -c 'import fuse' 2> /dev/null; then
12     WVSTART 'unable to import fuse; skipping test'
13     exit 0
14 fi
15
16 if test -n "$(type -p modprobe)" && ! modprobe fuse; then
17     echo 'Unable to load fuse module; skipping dependent tests.' 1>&2
18     exit 0
19 fi
20
21 if ! fusermount -V; then
22     echo 'skipping FUSE tests: fusermount does not appear to work'
23     exit 0
24 fi
25
26 if ! groups | grep -q fuse && test "$root_status" != root; then
27     echo 'skipping FUSE tests: you are not root and not in the fuse group'
28     exit 0
29 fi
30
31 top="$(WVPASS pwd)" || exit $?
32 tmpdir="$(WVPASS wvmktempdir)" || exit $?
33
34 export BUP_DIR="$tmpdir/bup"
35 export GIT_DIR="$tmpdir/bup"
36
37 bup() { "$top/bup" "$@"; }
38
39 # Some versions of bash's printf don't support the relevant date expansion.
40 savename()
41 {
42     readonly secs="$1"
43     WVPASS bup-python -c "from time import strftime, localtime; \
44        print strftime('%Y-%m-%d-%H%M%S', localtime($secs))"
45 }
46
47 WVPASS bup init
48 WVPASS cd "$tmpdir"
49
50 savestamp1=$(WVPASS bup-python -c 'import time; print int(time.time())') || exit $?
51 savestamp2=$(($savestamp1 + 1))
52
53 savename1="$(savename "$savestamp1")" || exit $?
54 savename2="$(savename "$savestamp2")" || exit $?
55
56 WVPASS mkdir src
57 WVPASS echo content > src/foo
58 WVPASS chmod 644 src/foo
59 WVPASS touch -t 201111111111 src/foo
60 # FUSE, python-fuse, something, can't handle negative epoch times.
61 # Use pre-epoch to make sure bup properly "bottoms out" at 0 for now.
62 WVPASS echo content > src/pre-epoch
63 WVPASS chmod 644 src/pre-epoch
64 WVPASS touch -t 196907202018 src/pre-epoch
65 WVPASS bup index src
66 WVPASS bup save -n src -d "$savestamp1" --strip src
67
68 WVSTART "basics"
69 WVPASS mkdir mnt
70 WVPASS bup fuse mnt
71
72 result=$(WVPASS ls mnt) || exit $?
73 WVPASSEQ src "$result"
74
75 result=$(WVPASS ls mnt/src) || exit $?
76 WVPASSEQ "$result" "$savename1
77 latest"
78
79 result=$(WVPASS ls mnt/src/latest) || exit $?
80 WVPASSEQ "$result" "foo
81 pre-epoch"
82
83 result=$(WVPASS cat mnt/src/latest/foo) || exit $?
84 WVPASSEQ "$result" "content"
85
86 WVPASS bup save -n src -d "$savestamp2" --strip src
87 result=$(WVPASS ls mnt/src) || exit $?
88 WVPASSEQ "$result" "$savename1
89 $savename2
90 latest"
91
92 WVPASS fusermount -uz mnt
93
94 WVSTART "extended metadata"
95 WVPASS bup fuse --meta mnt
96 result=$(TZ=UTC LC_ALL=C WVPASS ls -l mnt/src/latest/) || exit $?
97 readonly user=$(WVPASS id -un) || $?
98 readonly group=$(WVPASS id -gn) || $?
99 WVPASSEQ "$result" "total 1
100 -rw-r--r-- 1 $user $group 8 Nov 11  2011 foo
101 -rw-r--r-- 1 $user $group 8 Jan  1  1970 pre-epoch"
102
103 WVPASS fusermount -uz mnt
104 WVPASS rm -rf "$tmpdir"