]> arthur.barton.de Git - bup.git/blob - t/test-fuse.sh
fuse: adjust for python 3 and test there
[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 export TZ=UTC
48
49 WVPASS bup init
50 WVPASS cd "$tmpdir"
51
52 savestamp1=$(WVPASS bup-python -c 'import time; print(int(time.time()))') || exit $?
53 savestamp2=$(($savestamp1 + 1))
54
55 savename1="$(savename "$savestamp1")" || exit $?
56 savename2="$(savename "$savestamp2")" || exit $?
57
58 WVPASS mkdir src
59 WVPASS echo content > src/foo
60 WVPASS chmod 644 src/foo
61 WVPASS touch -t 201111111111 src/foo
62 # FUSE, python-fuse, something, can't handle negative epoch times.
63 # Use pre-epoch to make sure bup properly "bottoms out" at 0 for now.
64 WVPASS echo content > src/pre-epoch
65 WVPASS chmod 644 src/pre-epoch
66 WVPASS touch -t 196907202018 src/pre-epoch
67 WVPASS bup index src
68 WVPASS bup save -n src -d "$savestamp1" --strip src
69
70 WVSTART "basics"
71 WVPASS mkdir mnt
72 WVPASS bup fuse mnt
73
74 result=$(WVPASS ls mnt) || exit $?
75 WVPASSEQ src "$result"
76
77 result=$(WVPASS ls mnt/src) || exit $?
78 WVPASSEQ "$result" "$savename1
79 latest"
80
81 result=$(WVPASS ls mnt/src/latest) || exit $?
82 WVPASSEQ "$result" "foo
83 pre-epoch"
84
85 result=$(WVPASS cat mnt/src/latest/foo) || exit $?
86 WVPASSEQ "$result" "content"
87
88 # Right now we don't detect new saves.
89 WVPASS bup save -n src -d "$savestamp2" --strip src
90 result=$(WVPASS ls mnt/src) || exit $?
91 WVPASSEQ "$result" "$savename1
92 latest"
93
94 WVPASS fusermount -uz mnt
95
96 WVSTART "extended metadata"
97 WVPASS bup fuse --meta mnt
98 readonly user=$(WVPASS id -un) || $?
99 readonly group=$(WVPASS id -gn) || $?
100 result="$(stat --format='%A %U %G %x' mnt/src/latest/foo)"
101 WVPASSEQ "$result" "-rw-r--r-- $user $group 2011-11-11 11:11:00.000000000 +0000"
102 result="$(stat --format='%A %U %G %x' mnt/src/latest/pre-epoch)"
103 WVPASSEQ "$result" "-rw-r--r-- $user $group 1970-01-01 00:00:00.000000000 +0000"
104
105 WVPASS fusermount -uz mnt
106 WVPASS rm -rf "$tmpdir"