]> arthur.barton.de Git - bup.git/blob - t/test-meta.sh
Store metadata in the index, in bupindex.meta; only store unique values.
[bup.git] / t / test-meta.sh
1 #!/usr/bin/env bash
2 . wvtest.sh
3
4 TOP="$(pwd)"
5 export BUP_DIR="$TOP/buptest.tmp"
6
7 bup()
8 {
9     "$TOP/bup" "$@"
10 }
11
12 hardlink-sets()
13 {
14     "$TOP/t/hardlink-sets" "$@"
15 }
16
17 # Very simple metadata tests -- create a test tree then check that bup
18 # meta can reproduce the metadata correctly (according to bup xstat)
19 # via create, extract, start-extract, and finish-extract.  The current
20 # tests are crude, and this does not fully test devices, varying
21 # users/groups, acls, attrs, etc.
22
23 genstat()
24 {
25     (
26         export PATH="$TOP:$PATH" # pick up bup
27         # Skip atime (test elsewhere) to avoid the observer effect.
28         find . | sort | xargs bup xstat --exclude-fields ctime,atime,size
29     )
30 }
31
32 actually-root()
33 {
34     test "$(whoami)" == root -a -z "$FAKEROOTKEY"
35 }
36
37 force-delete()
38 {
39     if ! actually-root; then
40         rm -rf "$@"
41     else
42         # Go to greater lengths to deal with any test detritus.
43         for f in "$@"; do
44             test -e "$@" || continue
45             chattr -fR = "$@" || true
46             setfacl -Rb "$@"
47             rm -r "$@"
48         done
49     fi
50 }
51
52 test-src-create-extract()
53 {
54     # Test bup meta create/extract for ./src -> ./src-restore.
55     # Also writes to ./src-stat and ./src-restore-stat.
56     (
57         (cd src && WVPASS genstat) > src-stat
58         WVPASS bup meta --create --recurse --file src.meta src
59         # Test extract.
60         force-delete src-restore
61         mkdir src-restore
62         cd src-restore
63         WVPASS bup meta --extract --file ../src.meta
64         WVPASS test -d src
65         (cd src && genstat >../../src-restore-stat) || WVFAIL
66         WVPASS diff -U5 ../src-stat ../src-restore-stat
67         # Test start/finish extract.
68         force-delete src
69         WVPASS bup meta --start-extract --file ../src.meta
70         WVPASS test -d src
71         WVPASS bup meta --finish-extract --file ../src.meta
72         (cd src && genstat >../../src-restore-stat) || WVFAIL
73         WVPASS diff -U5 ../src-stat ../src-restore-stat
74     )
75 }
76
77 test-src-save-restore()
78 {
79     # Test bup save/restore metadata for ./src -> ./src-restore.  Also
80     # writes to ./src.bup.  Note that for now this just tests the
81     # restore below src/, in order to avoid having to worry about
82     # operations that require root (like chown /home).
83     (
84         set -x
85         rm -rf src.bup
86         mkdir src.bup
87         export BUP_DIR=$(pwd)/src.bup
88         WVPASS bup init
89         WVPASS bup index src
90         WVPASS bup save -t -n src src
91         # Test extract.
92         force-delete src-restore
93         mkdir src-restore
94         WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
95         WVPASS test -d src-restore/src
96         WVPASS "$TOP/t/compare-trees" -c src/ src-restore/src/
97         rm -rf src.bup
98         set +x
99     )
100 }
101
102 universal-cleanup()
103 {
104     if ! actually-root; then return 0; fi
105     cd "$TOP"
106     umount "$TOP/bupmeta.tmp/testfs" || true
107     umount "$TOP/bupmeta.tmp/testfs-limited" || true
108 }
109
110 universal-cleanup
111 trap universal-cleanup EXIT
112
113 setup-test-tree()
114 (
115     set -e
116     force-delete "$BUP_DIR"
117     force-delete "$TOP/bupmeta.tmp"
118     mkdir -p "$TOP/bupmeta.tmp/src"
119     cp -pPR Documentation cmd lib t "$TOP/bupmeta.tmp"/src
120
121     # Add some hard links for the general tests.
122     (
123         cd "$TOP/bupmeta.tmp"/src
124         touch hardlink-target
125         ln hardlink-target hardlink-1
126         ln hardlink-target hardlink-2
127         ln hardlink-target hardlink-3
128     )
129
130     # Add some trivial files for the index, modify, save tests.
131     (
132         cd "$TOP/bupmeta.tmp"/src
133         mkdir volatile
134         touch volatile/{1,2,3}
135     )
136
137     # Regression test for metadata sort order.  Previously, these two
138     # entries would sort in the wrong order because the metadata
139     # entries were being sorted by mangled name, but the index isn't.
140     dd if=/dev/zero of="$TOP/bupmeta.tmp"/src/foo bs=1k count=33
141     touch -d 2011-11-11 "$TOP/bupmeta.tmp"/src/foo
142     touch -d 2011-12-12 "$TOP/bupmeta.tmp"/src/foo-bar
143
144     t/mksock "$TOP/bupmeta.tmp/src/test-socket" || true
145 ) || WVFAIL
146
147 # Use the test tree to check bup meta.
148 WVSTART 'meta --create/--extract'
149 (
150     setup-test-tree
151     cd "$TOP/bupmeta.tmp"
152     test-src-create-extract
153
154     # Test a top-level file (not dir).
155     touch src-file
156     WVPASS bup meta -cf src-file.meta src-file
157     mkdir dest
158     cd dest
159     WVPASS bup meta -xf ../src-file.meta
160 )
161
162 # Use the test tree to check bup save/restore metadata.
163 WVSTART 'metadata save/restore (general)'
164 (
165     setup-test-tree
166     cd "$TOP/bupmeta.tmp"
167     test-src-save-restore
168 )
169
170 # Test that we pull the index (not filesystem) metadata for any
171 # unchanged files whenever we're saving other files in a given
172 # directory.
173 WVSTART 'metadata save/restore (using index metadata)'
174 (
175     setup-test-tree
176     cd "$TOP/bupmeta.tmp"
177
178     # ...for now -- might be a problem with hardlink restores that was
179     # causing noise wrt this test.
180     rm -rf src/hardlink*
181
182     # Pause here to keep the filesystem changes far enough away from
183     # the first index run that bup won't cap their index timestamps
184     # (see "bup help index" for more information).  Without this
185     # sleep, the compare-trees test below "Bup should *not* pick up
186     # these metadata..." may fail.
187     sleep 1
188
189     set -x
190     rm -rf src.bup
191     mkdir src.bup
192     export BUP_DIR=$(pwd)/src.bup
193     WVPASS bup init
194     WVPASS bup index src
195     WVPASS bup save -t -n src src
196
197     force-delete src-restore-1
198     mkdir src-restore-1
199     WVPASS bup restore -C src-restore-1 "/src/latest$(pwd)/"
200     WVPASS test -d src-restore-1/src
201     WVPASS "$TOP/t/compare-trees" -c src/ src-restore-1/src/
202
203     echo "blarg" > src/volatile/1
204     cp -a src/volatile/1 src-restore-1/src/volatile/
205     WVPASS bup index src
206
207     # Bup should *not* pick up these metadata changes.
208     touch src/volatile/2
209
210     WVPASS bup save -t -n src src
211
212     force-delete src-restore-2
213     mkdir src-restore-2
214     WVPASS bup restore -C src-restore-2 "/src/latest$(pwd)/"
215     WVPASS test -d src-restore-2/src
216     WVPASS "$TOP/t/compare-trees" -c src-restore-1/src/ src-restore-2/src/
217
218     rm -rf src.bup
219     set +x
220 )
221
222 setup-hardlink-test()
223 {
224     (
225         cd "$TOP/bupmeta.tmp"
226         rm -rf src src.bup
227         mkdir src src.bup
228         WVPASS bup init
229     )
230 }
231
232 hardlink-test-run-restore()
233 {
234     force-delete src-restore
235     mkdir src-restore
236     WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
237     WVPASS test -d src-restore/src
238 }
239
240 # Test hardlinks more carefully.
241 WVSTART 'metadata save/restore (hardlinks)'
242 (
243     set -e
244     set -x
245     export BUP_DIR="$TOP/bupmeta.tmp/src.bup"
246     force-delete "$TOP/bupmeta.tmp"
247     mkdir -p "$TOP/bupmeta.tmp"
248
249     cd "$TOP/bupmeta.tmp"
250
251     # Test trivial case - single hardlink.
252     setup-hardlink-test
253     (
254         cd "$TOP/bupmeta.tmp"/src
255         touch hardlink-target
256         ln hardlink-target hardlink-1
257     )
258     WVPASS bup index src
259     WVPASS bup save -t -n src src
260     hardlink-test-run-restore
261     WVPASS "$TOP/t/compare-trees" -c src/ src-restore/src/
262
263     # Test the case where the hardlink hasn't changed, but the tree
264     # needs to be saved again. i.e. the save-cmd.py "if hashvalid:"
265     # case.
266     (
267         cd "$TOP/bupmeta.tmp"/src
268         echo whatever > something-new
269     )
270     WVPASS bup index src
271     WVPASS bup save -t -n src src
272     hardlink-test-run-restore
273     WVPASS "$TOP/t/compare-trees" -c src/ src-restore/src/
274
275     # Test hardlink changes between index runs.
276     #
277     setup-hardlink-test
278     cd "$TOP/bupmeta.tmp"/src
279     touch hardlink-target-a
280     touch hardlink-target-b
281     ln hardlink-target-a hardlink-b-1
282     ln hardlink-target-a hardlink-a-1
283     cd ..
284     WVPASS bup index -vv src
285     rm src/hardlink-b-1
286     ln src/hardlink-target-b src/hardlink-b-1
287     WVPASS bup index -vv src
288     WVPASS bup save -t -n src src
289     hardlink-test-run-restore
290     echo ./src/hardlink-a-1 > hardlink-sets.expected
291     echo ./src/hardlink-target-a >> hardlink-sets.expected
292     echo >> hardlink-sets.expected
293     echo ./src/hardlink-b-1 >> hardlink-sets.expected
294     echo ./src/hardlink-target-b >> hardlink-sets.expected
295     (cd src-restore && hardlink-sets .) > hardlink-sets.restored
296     WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
297
298     # Test hardlink changes between index and save -- hardlink set [a
299     # b c d] changes to [a b] [c d].  At least right now bup should
300     # notice and recreate the latter.
301     setup-hardlink-test
302     cd "$TOP/bupmeta.tmp"/src
303     touch a
304     ln a b
305     ln a c
306     ln a d
307     cd ..
308     WVPASS bup index -vv src
309     rm src/c src/d
310     touch src/c
311     ln src/c src/d
312     WVPASS bup save -t -n src src
313     hardlink-test-run-restore
314     echo ./src/a > hardlink-sets.expected
315     echo ./src/b >> hardlink-sets.expected
316     echo >> hardlink-sets.expected
317     echo ./src/c >> hardlink-sets.expected
318     echo ./src/d >> hardlink-sets.expected
319     (cd src-restore && hardlink-sets .) > hardlink-sets.restored
320     WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
321
322     # Test that we don't link outside restore tree.
323     setup-hardlink-test
324     cd "$TOP/bupmeta.tmp"
325     mkdir src/a src/b
326     touch src/a/1
327     ln src/a/1 src/b/1
328     WVPASS bup index -vv src
329     WVPASS bup save -t -n src src
330     force-delete src-restore
331     mkdir src-restore
332     WVPASS bup restore -C src-restore "/src/latest$(pwd)/src/a/"
333     WVPASS test -e src-restore/1
334     echo -n > hardlink-sets.expected
335     (cd src-restore && hardlink-sets .) > hardlink-sets.restored
336     WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
337
338     # Test that we do link within separate sub-trees.
339     setup-hardlink-test
340     cd "$TOP/bupmeta.tmp"
341     mkdir src/a src/b
342     touch src/a/1
343     ln src/a/1 src/b/1
344     WVPASS bup index -vv src/a src/b
345     WVPASS bup save -t -n src src/a src/b
346     hardlink-test-run-restore
347     echo ./src/a/1 > hardlink-sets.expected
348     echo ./src/b/1 >> hardlink-sets.expected
349     (cd src-restore && hardlink-sets .) > hardlink-sets.restored
350     WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
351 )
352
353 WVSTART 'meta --edit'
354 (
355     force-delete "$TOP/bupmeta.tmp"
356     mkdir "$TOP/bupmeta.tmp"
357     cd "$TOP/bupmeta.tmp"
358     mkdir src
359     WVPASS bup meta -cf src.meta src
360
361     WVPASS bup meta --edit --set-uid 0 src.meta | WVPASS bup meta -tvvf - \
362         | WVPASS grep -qE '^uid: 0'
363     WVPASS bup meta --edit --set-uid 1000 src.meta | WVPASS bup meta -tvvf - \
364         | WVPASS grep -qE '^uid: 1000'
365
366     WVPASS bup meta --edit --set-gid 0 src.meta | WVPASS bup meta -tvvf - \
367         | WVPASS grep -qE '^gid: 0'
368     WVPASS bup meta --edit --set-gid 1000 src.meta | WVPASS bup meta -tvvf - \
369         | WVPASS grep -qE '^gid: 1000'
370
371     WVPASS bup meta --edit --set-user foo src.meta | WVPASS bup meta -tvvf - \
372         | WVPASS grep -qE '^user: foo'
373     WVPASS bup meta --edit --set-user bar src.meta | WVPASS bup meta -tvvf - \
374         | WVPASS grep -qE '^user: bar'
375     WVPASS bup meta --edit --unset-user src.meta | WVPASS bup meta -tvvf - \
376         | WVPASS grep -qE '^user:'
377     WVPASS bup meta --edit --set-user bar --unset-user src.meta \
378         | WVPASS bup meta -tvvf - | WVPASS grep -qE '^user:'
379     WVPASS bup meta --edit --unset-user --set-user bar src.meta \
380         | WVPASS bup meta -tvvf - | WVPASS grep -qE '^user: bar'
381
382     WVPASS bup meta --edit --set-group foo src.meta | WVPASS bup meta -tvvf - \
383         | WVPASS grep -qE '^group: foo'
384     WVPASS bup meta --edit --set-group bar src.meta | WVPASS bup meta -tvvf - \
385         | WVPASS grep -qE '^group: bar'
386     WVPASS bup meta --edit --unset-group src.meta | WVPASS bup meta -tvvf - \
387         | WVPASS grep -qE '^group:'
388     WVPASS bup meta --edit --set-group bar --unset-group src.meta \
389         | WVPASS bup meta -tvvf - | WVPASS grep -qE '^group:'
390     WVPASS bup meta --edit --unset-group --set-group bar src.meta \
391         | WVPASS bup meta -tvvf - | grep -qE '^group: bar'
392 )
393
394 # Test ownership restoration (when not root or fakeroot).
395 (
396     if test "$(whoami)" == root; then
397         exit 0
398     fi
399
400     WVSTART 'metadata (restoration of ownership)'
401     force-delete "$TOP/bupmeta.tmp"
402     mkdir "$TOP/bupmeta.tmp"
403     cd "$TOP/bupmeta.tmp"
404     touch src
405     WVPASS bup meta -cf src.meta src
406
407     mkdir dest
408     cd dest
409     # Make sure we don't change (or try to change) the user when not root.
410     WVPASS bup meta --edit --set-user root ../src.meta | WVPASS bup meta -x
411     WVPASS bup xstat src | WVPASS grep -qvE '^user: root'
412     rm -rf src
413     WVPASS bup meta --edit --unset-user --set-uid 0 ../src.meta \
414         | WVPASS bup meta -x
415     WVPASS bup xstat src | grep -qvE '^user: root'
416
417     # Make sure we can restore one of the user's groups.
418     last_group="$(python -c 'import os,grp; \
419       print grp.getgrgid(os.getgroups()[0])[0]')"
420     rm -rf src
421     WVPASS bup meta --edit --set-group "$last_group" ../src.meta \
422         | WVPASS bup meta -x
423     WVPASS bup xstat src | WVPASS grep -qE "^group: $last_group"
424
425     # Make sure we can restore one of the user's gids.
426     user_gids="$(id -G)"
427     last_gid="$(echo ${user_gids/* /})"
428     rm -rf src
429     WVPASS bup meta --edit --unset-group --set-gid "$last_gid" ../src.meta \
430         | WVPASS bup meta -x
431     WVPASS bup xstat src | WVPASS grep -qE "^gid: $last_gid"
432
433     # Test --numeric-ids (gid).
434     rm -rf src
435     current_gidx=$(bup meta -tvvf ../src.meta | grep -e '^gid:')
436     WVPASS bup meta --edit --set-group "$last_group" ../src.meta \
437         | WVPASS bup meta -x --numeric-ids
438     new_gidx=$(bup xstat src | grep -e '^gid:')
439     WVPASSEQ "$current_gidx" "$new_gidx"
440
441     # Test that restoring an unknown user works.
442     unknown_user=$("$TOP"/t/unknown-owner --user)
443     rm -rf src
444     current_uidx=$(bup meta -tvvf ../src.meta | grep -e '^uid:')
445     WVPASS bup meta --edit --set-user "$unknown_user" ../src.meta \
446         | WVPASS bup meta -x
447     new_uidx=$(bup xstat src | grep -e '^uid:')
448     WVPASSEQ "$current_uidx" "$new_uidx"
449
450     # Test that restoring an unknown group works.
451     unknown_group=$("$TOP"/t/unknown-owner --group)
452     rm -rf src
453     current_gidx=$(bup meta -tvvf ../src.meta | grep -e '^gid:')
454     WVPASS bup meta --edit --set-group "$unknown_group" ../src.meta \
455         | WVPASS bup meta -x
456     new_gidx=$(bup xstat src | grep -e '^gid:')
457     WVPASSEQ "$current_gidx" "$new_gidx"
458 )
459
460 # Test ownership restoration (when root or fakeroot).
461 (
462     if test "$(whoami)" != root; then
463         exit 0
464     fi
465
466     WVSTART 'metadata (restoration of ownership as root)'
467     force-delete "$TOP/bupmeta.tmp"
468     mkdir "$TOP/bupmeta.tmp"
469     cd "$TOP/bupmeta.tmp"
470     touch src
471     chown 0:0 src # In case the parent dir is sgid, etc.
472     WVPASS bup meta -cf src.meta src
473
474     mkdir dest
475     chmod 700 dest # so we can't accidentally do something insecure
476     cd dest
477
478     # Make sure we can restore a uid.
479     WVPASS bup meta --edit --unset-user --set-uid 42 ../src.meta \
480         | WVPASS bup meta -x
481     WVPASS bup xstat src | WVPASS grep -qE '^uid: 42'
482
483     # Make sure we can restore a gid.
484     WVPASS bup meta --edit --unset-group --set-gid 42 ../src.meta \
485         | WVPASS bup meta -x
486     WVPASS bup xstat src | WVPASS grep -qE '^gid: 42'
487
488     some_user=$("$TOP"/t/some-owner --user)
489     some_group=$("$TOP"/t/some-owner --group)
490
491     # Try to restore a user (and see that user trumps uid when uid is not 0).
492     WVPASS bup meta --edit --set-uid 42 --set-user "$some_user" ../src.meta \
493         | WVPASS bup meta -x
494     WVPASS bup xstat src | WVPASS grep -qE "^user: $some_user"
495
496     # Try to restore a group (and see that group trumps gid when gid is not 0).
497     WVPASS bup meta --edit --set-gid 42 --set-group "$some_group" ../src.meta \
498         | WVPASS bup meta -x
499     WVPASS bup xstat src | WVPASS grep -qE "^group: $some_user"
500
501     # Make sure a uid of 0 trumps a non-root user.
502     WVPASS bup meta --edit --set-user "$some_user" ../src.meta \
503         | WVPASS bup meta -x
504     WVPASS bup xstat src | WVPASS grep -qvE "^user: $some_user"
505     WVPASS bup xstat src | WVPASS grep -qE "^uid: 0"
506
507     # Make sure a gid of 0 trumps a non-root group.
508     WVPASS bup meta --edit --set-group "$some_user" ../src.meta \
509         | WVPASS bup meta -x
510     WVPASS bup xstat src | WVPASS grep -qvE "^group: $some_group"
511     WVPASS bup xstat src | WVPASS grep -qE "^gid: 0"
512
513     # Test --numeric-ids (gid).  Note the name 'root' is not handled
514     # specially, so we use that here as the test group name.  We
515     # assume that the root group's gid is never 42.
516     rm -rf src
517     WVPASS bup meta --edit --set-group root --set-gid 42 ../src.meta \
518         | WVPASS bup meta -x --numeric-ids
519     new_gidx=$(bup xstat src | grep -e '^gid:')
520     WVPASSEQ "$new_gidx" 'gid: 42'
521
522     # Test --numeric-ids (uid).  Note the name 'root' is not handled
523     # specially, so we use that here as the test user name.  We assume
524     # that the root user's uid is never 42.
525     rm -rf src
526     WVPASS bup meta --edit --set-user root --set-uid 42 ../src.meta \
527         | WVPASS bup meta -x --numeric-ids
528     new_uidx=$(bup xstat src | grep -e '^uid:')
529     WVPASSEQ "$new_uidx" 'uid: 42'
530
531     # Test that restoring an unknown user works.
532     unknown_user=$("$TOP"/t/unknown-owners --user)
533     rm -rf src
534     WVPASS bup meta --edit --set-uid 42 --set-user "$unknown_user" ../src.meta \
535         | WVPASS bup meta -x
536     new_uidx=$(bup xstat src | grep -e '^uid:')
537     WVPASSEQ "$new_uidx" 'uid: 42'
538
539     # Test that restoring an unknown group works.
540     unknown_group=$("$TOP"/t/unknown-owners --group)
541     rm -rf src
542     WVPASS bup meta --edit \
543         --set-gid 42 --set-group "$unknown_group" ../src.meta \
544         | WVPASS bup meta -x
545     new_gidx=$(bup xstat src | grep -e '^gid:')
546     WVPASSEQ "$new_gidx" 'gid: 42'
547 )
548
549 # Root-only tests that require an FS with all the trimmings: ACLs,
550 # Linux attr, Linux xattr, etc.
551 if actually-root; then
552     (
553         set -e
554         # Some cleanup handled in universal-cleanup() above.
555         # These tests are only likely to work under Linux for now
556         # (patches welcome).
557         [[ $(uname) =~ Linux ]] || exit 0
558
559         WVSTART 'meta - general (as root)'
560         setup-test-tree
561         cd "$TOP/bupmeta.tmp"
562
563         umount testfs || true
564         dd if=/dev/zero of=testfs.img bs=1M count=32
565         mke2fs -F -j -m 0 testfs.img
566         mkdir testfs
567         mount -o loop,acl,user_xattr testfs.img testfs
568         # Hide, so that tests can't create risks.
569         chown root:root testfs
570         chmod 0700 testfs
571
572         umount testfs-limited || true
573         dd if=/dev/zero of=testfs-limited.img bs=1M count=32
574         mkfs -t vfat testfs-limited.img
575         mkdir testfs-limited
576         mount -o loop,uid=root,gid=root,umask=0077 \
577             testfs-limited.img testfs-limited
578
579         #cp -a src testfs/src
580         cp -pPR src testfs/src
581         (cd testfs && test-src-create-extract)
582
583         WVSTART 'meta - atime (as root)'
584         force-delete testfs/src
585         mkdir testfs/src
586         (
587             mkdir testfs/src/foo
588             touch testfs/src/bar
589             PYTHONPATH="$TOP/lib" \
590                 python -c "from bup import xstat; \
591                 x = xstat.timespec_to_nsecs((42, 0));\
592                    xstat.utime('testfs/src/foo', (x, x));\
593                    xstat.utime('testfs/src/bar', (x, x));"
594             cd testfs
595             WVPASS bup meta -v --create --recurse --file src.meta src
596             bup meta -tvf src.meta
597             # Test extract.
598             force-delete src-restore
599             mkdir src-restore
600             cd src-restore
601             WVPASS bup meta --extract --file ../src.meta
602             WVPASSEQ "$(bup xstat --include-fields=atime src/foo)" "atime: 42"
603             WVPASSEQ "$(bup xstat --include-fields=atime src/bar)" "atime: 42"
604             # Test start/finish extract.
605             force-delete src
606             WVPASS bup meta --start-extract --file ../src.meta
607             WVPASS test -d src
608             WVPASS bup meta --finish-extract --file ../src.meta
609             WVPASSEQ "$(bup xstat --include-fields=atime src/foo)" "atime: 42"
610             WVPASSEQ "$(bup xstat --include-fields=atime src/bar)" "atime: 42"
611         )
612
613         WVSTART 'meta - Linux attr (as root)'
614         force-delete testfs/src
615         mkdir testfs/src
616         (
617             touch testfs/src/foo
618             mkdir testfs/src/bar
619             chattr +acdeijstuADST testfs/src/foo
620             chattr +acdeijstuADST testfs/src/bar
621             (cd testfs && test-src-create-extract)
622             # Test restoration to a limited filesystem (vfat).
623             (
624                 WVPASS bup meta --create --recurse --file testfs/src.meta \
625                     testfs/src
626                 force-delete testfs-limited/src-restore
627                 mkdir testfs-limited/src-restore
628                 cd testfs-limited/src-restore
629                 WVFAIL bup meta --extract --file ../../testfs/src.meta 2>&1 \
630                     | WVPASS grep -e '^Linux chattr:' \
631                     | WVPASS python -c \
632                       'import sys; exit(not len(sys.stdin.readlines()) == 2)'
633             )
634         )
635
636         WVSTART 'meta - Linux xattr (as root)'
637         force-delete testfs/src
638         mkdir testfs/src
639         (
640             touch testfs/src/foo
641             mkdir testfs/src/bar
642             attr -s foo -V bar testfs/src/foo
643             attr -s foo -V bar testfs/src/bar
644             (cd testfs && test-src-create-extract)
645
646             # Test restoration to a limited filesystem (vfat).
647             (
648                 WVPASS bup meta --create --recurse --file testfs/src.meta \
649                     testfs/src
650                 force-delete testfs-limited/src-restore
651                 mkdir testfs-limited/src-restore
652                 cd testfs-limited/src-restore
653                 WVFAIL bup meta --extract --file ../../testfs/src.meta 2>&1 \
654                     | WVPASS grep -e '^xattr\.set:' \
655                     | WVPASS python -c \
656                       'import sys; exit(not len(sys.stdin.readlines()) == 2)'
657             )
658         )
659
660         WVSTART 'meta - POSIX.1e ACLs (as root)'
661         force-delete testfs/src
662         mkdir testfs/src
663         (
664             touch testfs/src/foo
665             mkdir testfs/src/bar
666             setfacl -m u:root:r testfs/src/foo
667             setfacl -m u:root:r testfs/src/bar
668             (cd testfs && test-src-create-extract)
669
670             # Test restoration to a limited filesystem (vfat).
671             (
672                 WVPASS bup meta --create --recurse --file testfs/src.meta \
673                     testfs/src
674                 force-delete testfs-limited/src-restore
675                 mkdir testfs-limited/src-restore
676                 cd testfs-limited/src-restore
677                 WVFAIL bup meta --extract --file ../../testfs/src.meta 2>&1 \
678                     | WVPASS grep -e '^POSIX1e ACL applyto:' \
679                     | WVPASS python -c \
680                       'import sys; exit(not len(sys.stdin.readlines()) == 2)'
681             )
682         )
683     )
684 fi
685
686 exit 0