]> arthur.barton.de Git - bup.git/blob - test/ext/test-fuse
Update base_version to 0.34~ for 0.34 development
[bup.git] / test / ext / test-fuse
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3 . dev/lib.sh || exit $?
4
5 set -o pipefail
6
7 unset BLOCKSIZE BLOCK_SIZE DF_BLOCK_SIZE
8
9 top="$(WVPASS pwd)" || exit $?
10 bup() { "$top/bup" "$@"; }
11
12 # Note: this relies on the import checks happening first
13 # before the command-line is evaluated, and us doing an
14 # exit with status 2 on failures
15 bup fuse -h 2>/dev/null
16 if [ $? -eq 2 ]; then
17     WSKIP 'unable to import fuse/check version; skipping test'
18     exit 0
19 fi
20
21 if test -n "$(type -p modprobe)" && ! modprobe fuse; then
22     WVSKIP 'Unable to load fuse module; skipping dependent tests.'
23     exit 0
24 fi
25
26 if ! fusermount -V; then
27     WVSKIP 'skipping FUSE tests: fusermount does not appear to work'
28     exit 0
29 fi
30
31 if ! test -w /dev/fuse; then
32     WVSKIP 'skipping FUSE tests; no access to /dev/fuse'
33     exit 0
34 fi
35
36
37 clean_up() { fusermount -uz mnt || true; }
38 trap clean_up EXIT
39
40
41 top="$(WVPASS pwd)" || exit $?
42 tmpdir="$(WVPASS wvmktempdir)" || exit $?
43
44 export BUP_DIR="$tmpdir/bup"
45 export GIT_DIR="$tmpdir/bup"
46
47 # Some versions of bash's printf don't support the relevant date expansion.
48 savename()
49 {
50     readonly secs="$1"
51     WVPASS bup-cfg-py -c "from time import strftime, localtime; \
52        print(strftime('%Y-%m-%d-%H%M%S', localtime($secs)))"
53 }
54
55 export TZ=UTC
56
57 WVPASS bup init
58 WVPASS cd "$tmpdir"
59
60 savestamp1=$(WVPASS bup-cfg-py -c 'import time; print(int(time.time()))') || exit $?
61 savestamp2=$(($savestamp1 + 1))
62
63 savename1="$(savename "$savestamp1")" || exit $?
64 savename2="$(savename "$savestamp2")" || exit $?
65
66 WVPASS mkdir src
67 WVPASS echo content > src/foo
68 WVPASS chmod 644 src/foo
69 WVPASS touch -t 201111111111 src/foo
70 # FUSE, python-fuse, something, can't handle negative epoch times.
71 # Use pre-epoch to make sure bup properly "bottoms out" at 0 for now.
72 WVPASS echo content > src/pre-epoch
73 WVPASS chmod 644 src/pre-epoch
74 WVPASS touch -t 196907202018 src/pre-epoch
75 WVPASS bup index src
76 WVPASS bup save -n src -d "$savestamp1" --strip src
77
78 WVSTART "basics"
79 WVPASS mkdir mnt
80
81 bup fuse -f mnt &
82 fuse_pid=$!
83 while ! test -d mnt/src; do
84     sleep 0.1
85 done
86
87 result=$(WVPASS ls mnt) || exit $?
88 WVPASSEQ src "$result"
89
90 result=$(WVPASS ls mnt/src) || exit $?
91 WVPASSEQ "$result" "$savename1
92 latest"
93
94 result=$(WVPASS ls mnt/src/latest) || exit $?
95 WVPASSEQ "$result" "foo
96 pre-epoch"
97
98 result=$(WVPASS cat mnt/src/latest/foo) || exit $?
99 WVPASSEQ "$result" "content"
100
101 # Right now we don't detect new saves.
102 WVPASS bup save -n src -d "$savestamp2" --strip src
103 result=$(WVPASS ls mnt/src) || exit $?
104 WVPASSEQ "$result" "$savename1
105 latest"
106
107 WVPASS fusermount -uz mnt
108 WVPASS wait "$fuse_pid"
109 fuse_pid=''
110
111 WVSTART "extended metadata"
112
113 bup fuse -f --meta mnt &
114 fuse_pid=$!
115 while ! test -d mnt/src; do
116     sleep 0.1
117 done
118
119 readonly user=$(WVPASS id -un) || $?
120 readonly group=$(WVPASS id -gn) || $?
121 result="$(stat --format='%A %U %G %x' mnt/src/latest/foo)"
122 WVPASSEQ "$result" "-rw-r--r-- $user $group 2011-11-11 11:11:00.000000000 +0000"
123 result="$(stat --format='%A %U %G %x' mnt/src/latest/pre-epoch)"
124 WVPASSEQ "$result" "-rw-r--r-- $user $group 1970-01-01 00:00:00.000000000 +0000"
125
126 WVPASS fusermount -uz mnt
127 WVPASS rm -rf "$tmpdir"