]> arthur.barton.de Git - bup.git/blob - t/test-ls.sh
restore: test --sparse with zeros at 64k boundary
[bup.git] / t / test-ls.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3
4 set -o pipefail
5
6 top="$(WVPASS pwd)" || exit $?
7 tmpdir="$(WVPASS wvmktempdir)" || exit $?
8
9 export BUP_DIR="$tmpdir/bup"
10 export GIT_DIR="$tmpdir/bup"
11
12 bup() { "$top/bup" "$@"; }
13
14 export TZ=UTC
15
16 WVPASS bup init
17 WVPASS cd "$tmpdir"
18
19 WVPASS mkdir src
20 WVPASS touch src/.dotfile src/executable
21 WVPASS mkfifo src/fifo
22 WVPASS "$top"/t/mksock src/socket
23 WVPASS bup random 1k > src/file
24 WVPASS chmod u+x src/executable
25 WVPASS chmod -R u=rwX,g-rwx,o-rwx .
26 WVPASS touch -t 196907202018 src/.dotfile src/*
27 (WVPASS cd src; WVPASS ln -s file symlink) || exit $?
28 WVPASS touch -t 196907202018 src
29 WVPASS touch -t 196907202018 .
30 WVPASS bup index src
31 WVPASS bup save -n src src
32
33
34 WVSTART "ls (short)"
35
36 WVPASSEQ "$(WVPASS bup ls /)" "src"
37
38 WVPASSEQ "$(WVPASS bup ls -A /)" ".commit
39 .tag
40 src"
41
42 WVPASSEQ "$(WVPASS bup ls -AF /)" ".commit/
43 .tag/
44 src/"
45
46 WVPASSEQ "$(WVPASS bup ls -a /)" ".
47 ..
48 .commit
49 .tag
50 src"
51
52 WVPASSEQ "$(WVPASS bup ls -aF /)" "./
53 ../
54 .commit/
55 .tag/
56 src/"
57
58 WVPASSEQ "$(WVPASS bup ls src/latest/"$tmpdir"/src)" "executable
59 fifo
60 file
61 socket
62 symlink"
63
64 WVPASSEQ "$(WVPASS bup ls -A src/latest/"$tmpdir"/src)" ".dotfile
65 executable
66 fifo
67 file
68 socket
69 symlink"
70
71 WVPASSEQ "$(WVPASS bup ls -a src/latest/"$tmpdir"/src)" ".
72 ..
73 .dotfile
74 executable
75 fifo
76 file
77 socket
78 symlink"
79
80 WVPASSEQ "$(WVPASS bup ls -F src/latest/"$tmpdir"/src)" "executable*
81 fifo|
82 file
83 socket=
84 symlink@"
85
86 WVPASSEQ "$(WVPASS bup ls --file-type src/latest/"$tmpdir"/src)" "executable
87 fifo|
88 file
89 socket=
90 symlink@"
91
92 WVPASSEQ "$(WVPASS bup ls -d src/latest/"$tmpdir"/src)" "src/latest$tmpdir/src"
93
94
95 WVSTART "ls (long)"
96
97 WVPASSEQ "$(WVPASS bup ls -l / | tr -s ' ' ' ')" \
98 "d--------- ?/? 0 1970-01-01 00:00 src"
99
100 WVPASSEQ "$(WVPASS bup ls -lA / | tr -s ' ' ' ')" \
101 "d--------- ?/? 0 1970-01-01 00:00 .commit
102 d--------- ?/? 0 1970-01-01 00:00 .tag
103 d--------- ?/? 0 1970-01-01 00:00 src"
104
105 WVPASSEQ "$(WVPASS bup ls -lAF / | tr -s ' ' ' ')" \
106 "d--------- ?/? 0 1970-01-01 00:00 .commit/
107 d--------- ?/? 0 1970-01-01 00:00 .tag/
108 d--------- ?/? 0 1970-01-01 00:00 src/"
109
110 WVPASSEQ "$(WVPASS bup ls -la / | tr -s ' ' ' ')" \
111 "d--------- ?/? 0 1970-01-01 00:00 .
112 d--------- ?/? 0 1970-01-01 00:00 ..
113 d--------- ?/? 0 1970-01-01 00:00 .commit
114 d--------- ?/? 0 1970-01-01 00:00 .tag
115 d--------- ?/? 0 1970-01-01 00:00 src"
116
117 WVPASSEQ "$(WVPASS bup ls -laF / | tr -s ' ' ' ')" \
118 "d--------- ?/? 0 1970-01-01 00:00 ./
119 d--------- ?/? 0 1970-01-01 00:00 ../
120 d--------- ?/? 0 1970-01-01 00:00 .commit/
121 d--------- ?/? 0 1970-01-01 00:00 .tag/
122 d--------- ?/? 0 1970-01-01 00:00 src/"
123
124 symlink_mode="$(WVPASS ls -l src/symlink | cut -b -10)" || exit $?
125
126 symlink_bup_info="$(WVPASS bup ls -l src/latest"$tmpdir"/src | grep symlink)" \
127     || exit $?
128 symlink_date="$(WVPASS echo "$symlink_bup_info" \
129   | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')" \
130     || exit $?
131
132 if test "$(uname -s)" != NetBSD; then
133     symlink_size="$(WVPASS python -c "import os
134 print os.lstat('src/symlink').st_size")" || exit $?
135 else
136     # NetBSD appears to return varying sizes, so for now, just ignore it.
137     symlink_size="$(WVPASS echo "$symlink_bup_info" \
138       | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $1')" \
139         || exit $?
140 fi
141
142 uid="$(id -u)" || exit $?
143 gid="$(python -c 'import os; print os.stat("src").st_gid')" || exit $?
144 user="$(id -un)" || exit $?
145 group="$(python -c 'import grp, os;
146 print grp.getgrgid(os.stat("src").st_gid)[0]')" || exit $?
147
148 WVPASSEQ "$(bup ls -l src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
149 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
150 prw------- $user/$group 0 1969-07-20 20:18 fifo
151 -rw------- $user/$group 1024 1969-07-20 20:18 file
152 srwx------ $user/$group 0 1969-07-20 20:18 socket
153 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
154
155 WVPASSEQ "$(bup ls -la src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
156 "drwx------ $user/$group 0 1969-07-20 20:18 .
157 drwx------ $user/$group 0 1969-07-20 20:18 ..
158 -rw------- $user/$group 0 1969-07-20 20:18 .dotfile
159 -rwx------ $user/$group 0 1969-07-20 20:18 executable
160 prw------- $user/$group 0 1969-07-20 20:18 fifo
161 -rw------- $user/$group 1024 1969-07-20 20:18 file
162 srwx------ $user/$group 0 1969-07-20 20:18 socket
163 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
164
165 WVPASSEQ "$(bup ls -lA src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
166 "-rw------- $user/$group 0 1969-07-20 20:18 .dotfile
167 -rwx------ $user/$group 0 1969-07-20 20:18 executable
168 prw------- $user/$group 0 1969-07-20 20:18 fifo
169 -rw------- $user/$group 1024 1969-07-20 20:18 file
170 srwx------ $user/$group 0 1969-07-20 20:18 socket
171 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
172
173 WVPASSEQ "$(bup ls -lF src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
174 "-rwx------ $user/$group 0 1969-07-20 20:18 executable*
175 prw------- $user/$group 0 1969-07-20 20:18 fifo|
176 -rw------- $user/$group 1024 1969-07-20 20:18 file
177 srwx------ $user/$group 0 1969-07-20 20:18 socket=
178 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
179
180 WVPASSEQ "$(bup ls -l --file-type src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
181 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
182 prw------- $user/$group 0 1969-07-20 20:18 fifo|
183 -rw------- $user/$group 1024 1969-07-20 20:18 file
184 srwx------ $user/$group 0 1969-07-20 20:18 socket=
185 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
186
187 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
188 "-rwx------ $uid/$gid 0 1969-07-20 20:18 executable
189 prw------- $uid/$gid 0 1969-07-20 20:18 fifo
190 -rw------- $uid/$gid 1024 1969-07-20 20:18 file
191 srwx------ $uid/$gid 0 1969-07-20 20:18 socket
192 $symlink_mode $uid/$gid $symlink_size $symlink_date symlink -> file"
193
194 WVPASSEQ "$(bup ls -ld "src/latest$tmpdir/src" | tr -s ' ' ' ')" \
195 "drwx------ $user/$group 0 1969-07-20 20:18 src/latest$tmpdir/src"
196
197
198 WVSTART "ls (backup set - long)"
199 WVPASSEQ "$(bup ls -l src | cut -d' ' -f 1-2)" \
200 "l--------- ?/?
201 l--------- ?/?"
202
203
204 WVSTART "ls (dates TZ != UTC)"
205 export TZ=America/Chicago
206 symlink_date_central="$(bup ls -l src/latest"$tmpdir"/src | grep symlink)"
207 symlink_date_central="$(echo "$symlink_date_central" \
208   | perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')"
209 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
210 "-rwx------ $uid/$gid 0 1969-07-20 15:18 executable
211 prw------- $uid/$gid 0 1969-07-20 15:18 fifo
212 -rw------- $uid/$gid 1024 1969-07-20 15:18 file
213 srwx------ $uid/$gid 0 1969-07-20 15:18 socket
214 $symlink_mode $uid/$gid $symlink_size $symlink_date_central symlink -> file"
215 unset TZ
216
217
218 WVPASS rm -rf "$tmpdir"