2 . wvtest-bup.sh || exit $?
3 . dev/lib.sh || exit $?
7 root_status="$(dev/root-status)" || exit $?
9 TOP="$(WVPASS pwd)" || exit $?
10 export PATH="$TOP/test/bin:$PATH"
11 tmpdir="$(WVPASS wvmktempdir)" || exit $?
12 export BUP_DIR="$tmpdir/bup"
14 # Assume that mvmktempdir will always use the same dir.
15 timestamp_resolutions="$(dev/ns-timestamp-resolutions "$tmpdir/canary")" \
17 atime_resolution="$(echo $timestamp_resolutions | WVPASS cut -d' ' -f 1)" \
19 mtime_resolution="$(echo $timestamp_resolutions | WVPASS cut -d' ' -f 2)" \
21 WVPASS rm "$tmpdir/canary"
30 "$TOP/dev/hardlink-sets" "$@"
35 "$TOP/dev/id-other-than" "$@"
38 # Very simple metadata tests -- create a test tree then check that bup
39 # meta can reproduce the metadata correctly (according to bup xstat)
40 # via create, extract, start-extract, and finish-extract. The current
41 # tests are crude, and this does not fully test devices, varying
42 # users/groups, acls, attrs, etc.
47 export PATH="$TOP/bin:$PATH" # pick up bup
49 # Skip atime (test elsewhere) to avoid the observer effect.
50 WVPASS find . -print0 | WVPASS sort-z \
51 | WVPASS xargs -0 bup xstat \
52 --mtime-resolution "$mtime_resolution"ns \
53 --exclude-fields ctime,atime,size
57 test-src-create-extract()
59 # Test bup meta create/extract for ./src -> ./src-restore.
60 # Also writes to ./src-stat and ./src-restore-stat.
62 (WVPASS cd src; WVPASS genstat) > src-stat || exit $?
63 WVPASS bup meta --create --recurse --file src.meta src
65 WVPASS force-delete src-restore
66 WVPASS mkdir src-restore
68 WVPASS bup meta --extract --file ../src.meta
70 (WVPASS cd src; WVPASS genstat >../../src-restore-stat) || exit $?
71 WVPASS diff -U5 ../src-stat ../src-restore-stat
72 # Test start/finish extract.
73 WVPASS force-delete src
74 WVPASS bup meta --start-extract --file ../src.meta
76 WVPASS bup meta --finish-extract --file ../src.meta
77 (WVPASS cd src; WVPASS genstat >../../src-restore-stat) || exit $?
78 WVPASS diff -U5 ../src-stat ../src-restore-stat
82 test-src-save-restore()
84 # Test bup save/restore metadata for ./src -> ./src-restore. Also
85 # writes to BUP_DIR. Note that for now this just tests the
86 # restore below src/, in order to avoid having to worry about
87 # operations that require root (like chown /home).
89 WVPASS rm -rf "$BUP_DIR"
92 WVPASS bup save -t -n src src
94 WVPASS force-delete src-restore
95 WVPASS mkdir src-restore
96 WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
97 WVPASS test -d src-restore/src
98 WVPASS "$TOP/dev/compare-trees" -c src/ src-restore/src/
105 WVPASS "$TOP/dev/sync-tree" "$TOP/test/sampledata/" "$tmpdir/src/"
107 # Add some hard links for the general tests.
109 WVPASS cd "$tmpdir"/src
110 WVPASS touch hardlink-target
111 WVPASS ln hardlink-target hardlink-1
112 WVPASS ln hardlink-target hardlink-2
113 WVPASS ln hardlink-target hardlink-3
116 # Add some trivial files for the index, modify, save tests.
118 WVPASS cd "$tmpdir"/src
119 WVPASS mkdir volatile
120 WVPASS touch volatile/{1,2,3}
123 # Regression test for metadata sort order. Previously, these two
124 # entries would sort in the wrong order because the metadata
125 # entries were being sorted by mangled name, but the index isn't.
126 WVPASS dd if=/dev/zero of="$tmpdir"/src/foo bs=1k count=33
127 WVPASS touch -t 201111111111 "$tmpdir"/src/foo
128 WVPASS touch -t 201112121111 "$tmpdir"/src/foo-bar
130 dev/mksock "$tmpdir"/src/test-socket || true
133 # Use the test tree to check bup meta.
134 WVSTART 'meta --create/--extract'
136 tmpdir="$(WVPASS wvmktempdir)" || exit $?
137 export BUP_DIR="$tmpdir/bup"
138 WVPASS setup-test-tree
140 WVPASS test-src-create-extract
142 # Test a top-level file (not dir).
143 WVPASS touch src-file
144 WVPASS bup meta -cf src-file.meta src-file
147 WVPASS bup meta -xf ../src-file.meta
148 WVPASS rm -r "$tmpdir"
151 # Use the test tree to check bup save/restore metadata.
152 WVSTART 'metadata save/restore (general)'
154 tmpdir="$(WVPASS wvmktempdir)" || exit $?
155 export BUP_DIR="$tmpdir/bup"
156 WVPASS setup-test-tree
158 WVPASS test-src-save-restore
160 # Test a deeper subdir/ to make sure top-level non-dir metadata is
161 # restored correctly. We need at least one dir and one non-dir at
163 WVPASS test -d src/var/lib/bup
164 WVPASS test -f src/var/lib/bup/git.py
165 WVPASS rm -rf "$BUP_DIR"
167 WVPASS touch -t 201111111111 src-restore # Make sure the top won't match.
169 WVPASS bup save -t -n src src
170 WVPASS force-delete src-restore
171 WVPASS bup restore -C src-restore "/src/latest$(pwd)/src/var/."
172 WVPASS touch -t 201211111111 src-restore # Make sure the top won't match.
173 # Check that the only difference is the top dir.
174 WVFAIL $TOP/dev/compare-trees -c src/var/ src-restore/ > tmp-compare-trees
175 WVPASSEQ $(cat tmp-compare-trees | wc -l) 1
176 # The number of rsync status characters varies, so accept any
177 # number of trailing dots. For example OS X native rsync produces
178 # 9, but Homebrew's produces 12, while on other platforms, 11 is
180 expected_diff_rx='^\.d\.\.t\.\.\.(\.)+ \./$'
181 if ! grep -qE "$expected_diff_rx" tmp-compare-trees; then
182 echo -n 'tmp-compare-trees: ' 1>&2
183 cat tmp-compare-trees 1>&2
185 WVPASS grep -qE "$expected_diff_rx" tmp-compare-trees
186 WVPASS rm -r "$tmpdir"
189 # Test that we pull the index (not filesystem) metadata for any
190 # unchanged files whenever we're saving other files in a given
192 WVSTART 'metadata save/restore (using index metadata)'
194 tmpdir="$(WVPASS wvmktempdir)" || exit $?
195 export BUP_DIR="$tmpdir/bup"
196 WVPASS setup-test-tree
199 # ...for now -- might be a problem with hardlink restores that was
200 # causing noise wrt this test.
201 WVPASS rm -rf src/hardlink*
203 # Pause here to keep the filesystem changes far enough away from
204 # the first index run that bup won't cap their index timestamps
205 # (see "bup help index" for more information). Without this
206 # sleep, the compare-trees test below "Bup should *not* pick up
207 # these metadata..." may fail.
210 WVPASS rm -rf "$BUP_DIR"
213 WVPASS bup save -t -n src src
215 WVPASS force-delete src-restore-1
216 WVPASS mkdir src-restore-1
217 WVPASS bup restore -C src-restore-1 "/src/latest$(pwd)/"
218 WVPASS test -d src-restore-1/src
219 WVPASS "$TOP/dev/compare-trees" -c src/ src-restore-1/src/
221 WVPASS echo "blarg" > src/volatile/1
222 WVPASS cp -pP src/volatile/1 src-restore-1/src/volatile/
225 # Bup should *not* pick up these metadata changes.
226 WVPASS touch src/volatile/2
228 WVPASS bup save -t -n src src
230 WVPASS force-delete src-restore-2
231 WVPASS mkdir src-restore-2
232 WVPASS bup restore -C src-restore-2 "/src/latest$(pwd)/"
233 WVPASS test -d src-restore-2/src
234 WVPASS "$TOP/dev/compare-trees" -c src-restore-1/src/ src-restore-2/src/
236 WVPASS rm -r "$tmpdir"
241 setup-hardlink-test()
243 WVPASS rm -rf "$tmpdir/src" "$BUP_DIR"
245 WVPASS mkdir "$tmpdir/src"
248 hardlink-test-run-restore()
250 WVPASS force-delete src-restore
251 WVPASS mkdir src-restore
252 WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
253 WVPASS test -d src-restore/src
256 # Test hardlinks more carefully.
257 WVSTART 'metadata save/restore (hardlinks)'
259 tmpdir="$(WVPASS wvmktempdir)" || exit $?
260 export BUP_DIR="$tmpdir/bup"
262 WVPASS setup-hardlink-test
265 # Test trivial case - single hardlink.
268 WVPASS touch hardlink-target
269 WVPASS ln hardlink-target hardlink-1
272 WVPASS bup save -t -n src src
273 WVPASS hardlink-test-run-restore
274 WVPASS "$TOP/dev/compare-trees" -c src/ src-restore/src/
276 # Test the case where the hardlink hasn't changed, but the tree
277 # needs to be saved again. i.e. the save-cmd.py "if hashvalid:"
281 WVPASS echo whatever > something-new
284 WVPASS bup save -t -n src src
285 WVPASS hardlink-test-run-restore
286 WVPASS "$TOP/dev/compare-trees" -c src/ src-restore/src/
288 # Test hardlink changes between index runs.
290 WVPASS setup-hardlink-test
292 WVPASS touch hardlink-target-a
293 WVPASS touch hardlink-target-b
294 WVPASS ln hardlink-target-a hardlink-b-1
295 WVPASS ln hardlink-target-a hardlink-a-1
297 WVPASS bup index -vv src
298 WVPASS rm src/hardlink-b-1
299 WVPASS ln src/hardlink-target-b src/hardlink-b-1
300 WVPASS bup index -vv src
301 WVPASS bup save -t -n src src
302 WVPASS hardlink-test-run-restore
303 WVPASS echo ./src/hardlink-a-1 > hardlink-sets.expected
304 WVPASS echo ./src/hardlink-target-a >> hardlink-sets.expected
305 WVPASS echo >> hardlink-sets.expected
306 WVPASS echo ./src/hardlink-b-1 >> hardlink-sets.expected
307 WVPASS echo ./src/hardlink-target-b >> hardlink-sets.expected
308 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
310 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
312 # Test hardlink changes between index and save -- hardlink set [a
313 # b c d] changes to [a b] [c d]. At least right now bup should
314 # notice and recreate the latter.
315 WVPASS setup-hardlink-test
316 WVPASS cd "$tmpdir"/src
322 WVPASS bup index -vv src
323 WVPASS rm src/c src/d
325 WVPASS ln src/c src/d
326 WVPASS bup save -t -n src src
327 WVPASS hardlink-test-run-restore
328 WVPASS echo ./src/a > hardlink-sets.expected
329 WVPASS echo ./src/b >> hardlink-sets.expected
330 WVPASS echo >> hardlink-sets.expected
331 WVPASS echo ./src/c >> hardlink-sets.expected
332 WVPASS echo ./src/d >> hardlink-sets.expected
333 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
335 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
337 # Test that we don't link outside restore tree.
338 WVPASS setup-hardlink-test
340 WVPASS mkdir src/a src/b
342 WVPASS ln src/a/1 src/b/1
343 WVPASS bup index -vv src
344 WVPASS bup save -t -n src src
345 WVPASS force-delete src-restore
346 WVPASS mkdir src-restore
347 WVPASS bup restore -C src-restore "/src/latest$(pwd)/src/a/"
348 WVPASS test -e src-restore/1
349 WVPASS echo -n > hardlink-sets.expected
350 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
352 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
354 # Test that we do link within separate sub-trees.
355 WVPASS setup-hardlink-test
357 WVPASS mkdir src/a src/b
359 WVPASS ln src/a/1 src/b/1
360 WVPASS bup index -vv src/a src/b
361 WVPASS bup save -t -n src src/a src/b
362 WVPASS hardlink-test-run-restore
363 WVPASS echo ./src/a/1 > hardlink-sets.expected
364 WVPASS echo ./src/b/1 >> hardlink-sets.expected
365 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
367 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
369 WVPASS rm -r "$tmpdir"
373 WVSTART 'meta --edit'
375 tmpdir="$(WVPASS wvmktempdir)" || exit $?
379 WVPASS bup meta -cf src.meta src
381 WVPASS bup meta --edit --set-uid 0 src.meta | WVPASS bup meta -tvvf - \
382 | WVPASS grep -qE '^uid: 0'
383 WVPASS bup meta --edit --set-uid 1000 src.meta | WVPASS bup meta -tvvf - \
384 | WVPASS grep -qE '^uid: 1000'
386 WVPASS bup meta --edit --set-gid 0 src.meta | WVPASS bup meta -tvvf - \
387 | WVPASS grep -qE '^gid: 0'
388 WVPASS bup meta --edit --set-gid 1000 src.meta | WVPASS bup meta -tvvf - \
389 | WVPASS grep -qE '^gid: 1000'
391 WVPASS bup meta --edit --set-user foo src.meta | WVPASS bup meta -tvvf - \
392 | WVPASS grep -qE '^user: foo'
393 WVPASS bup meta --edit --set-user bar src.meta | WVPASS bup meta -tvvf - \
394 | WVPASS grep -qE '^user: bar'
395 WVPASS bup meta --edit --unset-user src.meta | WVPASS bup meta -tvvf - \
396 | WVPASS grep -qE '^user:'
397 WVPASS bup meta --edit --set-user bar --unset-user src.meta \
398 | WVPASS bup meta -tvvf - | WVPASS grep -qE '^user:'
399 WVPASS bup meta --edit --unset-user --set-user bar src.meta \
400 | WVPASS bup meta -tvvf - | WVPASS grep -qE '^user: bar'
402 WVPASS bup meta --edit --set-group foo src.meta | WVPASS bup meta -tvvf - \
403 | WVPASS grep -qE '^group: foo'
404 WVPASS bup meta --edit --set-group bar src.meta | WVPASS bup meta -tvvf - \
405 | WVPASS grep -qE '^group: bar'
406 WVPASS bup meta --edit --unset-group src.meta | WVPASS bup meta -tvvf - \
407 | WVPASS grep -qE '^group:'
408 WVPASS bup meta --edit --set-group bar --unset-group src.meta \
409 | WVPASS bup meta -tvvf - | WVPASS grep -qE '^group:'
410 WVPASS bup meta --edit --unset-group --set-group bar src.meta \
411 | WVPASS bup meta -tvvf - | grep -qE '^group: bar'
413 WVPASS rm -r "$tmpdir"
417 WVSTART 'meta --no-recurse'
419 tmpdir="$(WVPASS wvmktempdir)" || exit $?
423 WVPASS touch src/foo/{1,2,3}
424 WVPASS bup meta -cf src.meta src
425 WVPASSEQ "$(bup meta -tf src.meta | LC_ALL=C sort)" "src/
430 WVPASS bup meta --no-recurse -cf src.meta src
431 WVPASSEQ "$(bup meta -tf src.meta | LC_ALL=C sort)" "src/"
432 WVPASS rm -r "$tmpdir"
435 # Test ownership restoration (when not root or fakeroot).
437 if [ "$root_status" != none ]; then
441 tmpdir="$(WVPASS wvmktempdir)" || exit $?
443 # FIXME: binary groups
444 first_group="$(WVPASS bup-cfg-py -c 'import os,grp; \
445 print(grp.getgrgid(os.getgroups()[0])[0])')" || exit $?
446 last_group="$(bup-cfg-py -c 'import os,grp; \
447 print(grp.getgrgid(os.getgroups()[-1])[0])')" || exit $?
448 last_group_erx="$(escape-erx "$last_group")"
450 WVSTART 'metadata (restoration of ownership)'
453 # Some systems always assign the parent dir group to new paths
454 # (sgid). Make sure the group is one we're in.
455 WVPASS chgrp -R "$first_group" src
457 WVPASS bup meta -cf src.meta src
461 # Make sure we don't change (or try to change) the user when not root.
462 WVPASS bup meta --edit --set-user root ../src.meta | WVPASS bup meta -x
463 WVPASS bup xstat src | WVPASS grep -qvE '^user: root'
465 WVPASS bup meta --edit --unset-user --set-uid 0 ../src.meta \
467 WVPASS bup xstat src | WVPASS grep -qvE '^user: root'
469 # Make sure we can restore one of the user's groups.
471 WVPASS bup meta --edit --set-group "$last_group" ../src.meta \
473 WVPASS bup xstat src | WVPASS grep -qE "^group: $last_group_erx"
475 # Make sure we can restore one of the user's gids.
476 user_gids="$(id -G)" || exit $?
477 last_gid="$(echo ${user_gids/* /})" || exit $?
479 WVPASS bup meta --edit --unset-group --set-gid "$last_gid" ../src.meta \
481 WVPASS bup xstat src | WVPASS grep -qE "^gid: $last_gid"
483 # Test --numeric-ids (gid).
485 current_gidx=$(bup meta -tvvf ../src.meta | grep -ae '^gid:') || exit $?
486 WVPASS bup meta --edit --set-group "$last_group" ../src.meta \
487 | WVPASS bup meta -x --numeric-ids
488 new_gidx=$(bup xstat src | grep -ae '^gid:') || exit $?
489 WVPASSEQ "$current_gidx" "$new_gidx"
491 # Test that restoring an unknown user works.
492 unknown_user=$("$TOP"/dev/unknown-owner --user) || exit $?
494 current_uidx=$(bup meta -tvvf ../src.meta | grep -ae '^uid:') || exit $?
495 WVPASS bup meta --edit --set-user "$unknown_user" ../src.meta \
497 new_uidx=$(bup xstat src | grep -ae '^uid:') || exit $?
498 WVPASSEQ "$current_uidx" "$new_uidx"
500 # Test that restoring an unknown group works.
501 unknown_group=$("$TOP"/dev/unknown-owner --group) || exit $?
503 current_gidx=$(bup meta -tvvf ../src.meta | grep -ae '^gid:') || exit $?
504 WVPASS bup meta --edit --set-group "$unknown_group" ../src.meta \
506 new_gidx=$(bup xstat src | grep -ae '^gid:') || exit $?
507 WVPASSEQ "$current_gidx" "$new_gidx"
509 WVPASS rm -r "$tmpdir"
513 # Test ownership restoration (when root or fakeroot).
515 if [ "$root_status" = none ]; then
519 tmpdir="$(WVPASS wvmktempdir)" || exit $?
521 uid=$(WVPASS id -un) || exit $?
522 gid=$(WVPASS id -gn) || exit $?
524 WVSTART 'metadata (restoration of ownership as root)'
527 WVPASS chown "$uid:$gid" src # In case the parent dir is sgid, etc.
528 WVPASS bup meta -cf src.meta src
531 WVPASS chmod 700 dest # so we can't accidentally do something insecure
534 other_uinfo="$(id-other-than --user "$uid")" || exit $?
535 other_user="${other_uinfo%%:*}"
536 other_uid="${other_uinfo##*:}"
538 other_ginfo="$(id-other-than --group "$gid")" || exit $?
539 other_group="${other_ginfo%%:*}"
540 other_gid="${other_ginfo##*:}"
542 # Make sure we can restore a uid (must be in /etc/passwd b/c cygwin).
543 WVPASS bup meta --edit --unset-user --set-uid "$other_uid" ../src.meta \
545 WVPASS bup xstat src | WVPASS grep -qE "^uid: $other_uid"
547 # Make sure we can restore a gid (must be in /etc/group b/c cygwin).
548 WVPASS bup meta --edit --unset-group --set-gid "$other_gid" ../src.meta \
550 WVPASS bup xstat src | WVPASS grep -qE "^gid: $other_gid"
552 other_uinfo2="$(id-other-than --user "$(id -un)" "$other_user")" || exit $?
553 other_user2="${other_uinfo2%%:*}"
554 other_user2_erx="$(escape-erx "$other_user2")" || exit $?
555 other_uid2="${other_uinfo2##*:}"
557 other_ginfo2="$(id-other-than --group "$(id -gn)" "$other_group")" || exit $?
558 other_group2="${other_ginfo2%%:*}"
559 other_group2_erx="$(escape-erx "$other_group2")" || exit $?
560 other_gid2="${other_ginfo2##*:}"
562 # Try to restore a user (and see that user trumps uid when uid is not 0).
563 WVPASS bup meta --edit \
564 --set-uid "$other_uid" --set-user "$other_user2" ../src.meta \
566 WVPASS bup xstat src | WVPASS grep -qE "^user: $other_user2_erx"
568 # Try to restore a group (and see that group trumps gid when gid is not 0).
569 WVPASS bup meta --edit \
570 --set-gid "$other_gid" --set-group "$other_group2" ../src.meta \
572 WVPASS bup xstat src | WVPASS grep -qE "^group: $other_group2_erx"
574 # Test --numeric-ids (uid). Note the name 'root' is not handled
575 # specially, so we use that here as the test user name. We assume
576 # that the root user's uid is never 42.
578 WVPASS bup meta --edit --set-user root --set-uid "$other_uid" ../src.meta \
579 | WVPASS bup meta -x --numeric-ids
580 new_uidx=$(bup xstat src | grep -e '^uid:') || exit $?
581 WVPASSEQ "$new_uidx" "uid: $other_uid"
583 # Test --numeric-ids (gid). Note the name 'root' is not handled
584 # specially, so we use that here as the test group name. We
585 # assume that the root group's gid is never 42.
587 WVPASS bup meta --edit --set-group root --set-gid "$other_gid" ../src.meta \
588 | WVPASS bup meta -x --numeric-ids
589 new_gidx=$(bup xstat src | grep -e '^gid:') || exit $?
590 WVPASSEQ "$new_gidx" "gid: $other_gid"
592 # Test that restoring an unknown user works.
593 unknown_user=$("$TOP"/dev/unknown-owner --user) || exit $?
595 WVPASS bup meta --edit \
596 --set-uid "$other_uid" --set-user "$unknown_user" ../src.meta \
598 new_uidx=$(bup xstat src | grep -e '^uid:') || exit $?
599 WVPASSEQ "$new_uidx" "uid: $other_uid"
601 # Test that restoring an unknown group works.
602 unknown_group=$("$TOP"/dev/unknown-owner --group) || exit $?
604 WVPASS bup meta --edit \
605 --set-gid "$other_gid" --set-group "$unknown_group" ../src.meta \
607 new_gidx=$(bup xstat src | grep -e '^gid:') || exit $?
608 WVPASSEQ "$new_gidx" "gid: $other_gid"
610 if ! [[ $(uname) =~ CYGWIN ]]; then
611 # For now, skip these on Cygwin because it doesn't allow
612 # restoring an unknown uid/gid.
614 # Make sure a uid of 0 trumps a non-root user.
615 WVPASS bup meta --edit --set-user "$other_user2" ../src.meta \
617 WVPASS bup xstat src | WVPASS grep -qvE "^user: $other_user2_erx"
618 WVPASS bup xstat src | WVPASS grep -qE "^uid: 0"
620 # Make sure a gid of 0 trumps a non-root group.
621 WVPASS bup meta --edit --set-group "$other_group2" ../src.meta \
623 WVPASS bup xstat src | WVPASS grep -qvE "^group: $other_group2_erx"
624 WVPASS bup xstat src | WVPASS grep -qE "^gid: 0"
627 WVPASS rm -r "$tmpdir"
632 # Root-only tests that require an FS with all the trimmings: ACLs,
633 # Linux attr, Linux xattr, etc.
634 if [ "$root_status" = root ]; then
636 # Some cleanup handled in universal-cleanup() above.
637 # These tests are only likely to work under Linux for now
639 [[ $(uname) =~ Linux ]] || exit 0
641 if ! modprobe loop; then
642 echo 'Unable to load loopback module; skipping dependent tests.' 1>&2
646 testfs="$(WVPASS wvmkmountpt)" || exit $?
647 testfs_limited="$(WVPASS wvmkmountpt)" || exit $?
648 tmpdir="$(WVPASS wvmktempdir)" || exit $?
649 export BUP_DIR="$tmpdir/bup"
651 WVSTART 'meta - general (as root)'
652 WVPASS setup-test-tree
656 WVPASS dd if=/dev/zero of=testfs.img bs=1M count=32
657 # Make sure we have all the options the chattr test needs
658 # (i.e. create a "normal" ext4 filesystem).
659 WVPASS mke2fs -F -m 0 \
661 -O has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize \
663 WVPASS mount -o loop,acl,user_xattr testfs.img "$testfs"
664 # Hide, so that tests can't create risks.
665 WVPASS chown root:root "$testfs"
666 WVPASS chmod 0700 "$testfs"
668 umount "$testfs_limited"
669 WVPASS dd if=/dev/zero of=testfs-limited.img bs=1M count=32
670 WVPASS mkfs -t vfat testfs-limited.img
671 WVPASS mount -o loop,uid=root,gid=root,umask=0077 \
672 testfs-limited.img "$testfs_limited"
674 WVPASS cp -pPR src "$testfs"/src
675 (WVPASS cd "$testfs"; WVPASS test-src-create-extract) || exit $?
677 WVSTART 'meta - atime (as root)'
678 WVPASS force-delete "$testfs"/src
679 WVPASS mkdir "$testfs"/src
681 WVPASS mkdir "$testfs"/src/foo
682 WVPASS touch "$testfs"/src/bar
683 WVPASS bup-python -c "from bup import xstat; \
684 x = xstat.timespec_to_nsecs((42, 0));\
685 xstat.utime(b'$testfs/src/foo', (x, x));\
686 xstat.utime(b'$testfs/src/bar', (x, x));"
688 WVPASS bup meta -v --create --recurse --file src.meta src
689 WVPASS bup meta -tvf src.meta
691 WVPASS force-delete src-restore
692 WVPASS mkdir src-restore
693 WVPASS cd src-restore
694 WVPASS bup meta --extract --file ../src.meta
695 WVPASSEQ "$(bup xstat --include-fields=atime src/foo)" "atime: 42"
696 WVPASSEQ "$(bup xstat --include-fields=atime src/bar)" "atime: 42"
697 # Test start/finish extract.
698 WVPASS force-delete src
699 WVPASS bup meta --start-extract --file ../src.meta
701 WVPASS bup meta --finish-extract --file ../src.meta
702 WVPASSEQ "$(bup xstat --include-fields=atime src/foo)" "atime: 42"
703 WVPASSEQ "$(bup xstat --include-fields=atime src/bar)" "atime: 42"
706 WVSTART 'meta - Linux attr (as root)'
707 WVPASS force-delete "$testfs"/src
708 WVPASS mkdir "$testfs"/src
710 WVPASS touch "$testfs"/src/foo
711 WVPASS mkdir "$testfs"/src/bar
712 WVPASS chattr +acdeijstuADS "$testfs"/src/foo
713 WVPASS chattr +acdeijstuADST "$testfs"/src/bar
714 (WVPASS cd "$testfs"; WVPASS test-src-create-extract) || exit $?
715 # Test restoration to a limited filesystem (vfat).
717 WVPASS bup meta --create --recurse --file "$testfs"/src.meta \
719 WVPASS force-delete "$testfs_limited"/src-restore
720 WVPASS mkdir "$testfs_limited"/src-restore
721 WVPASS cd "$testfs_limited"/src-restore
722 WVFAIL bup meta --extract --file "$testfs"/src.meta 2>&1 \
723 | WVPASS grep -e '^Linux chattr:' \
724 | WVPASS bup-cfg-py -c \
725 'import sys; exit(not len(sys.stdin.readlines()) == 3)'
729 WVSTART 'meta - Linux xattr (as root)'
730 WVPASS force-delete "$testfs"/src
731 WVPASS mkdir "$testfs"/src
732 WVPASS touch "$testfs"/src/foo
733 WVPASS mkdir "$testfs"/src/bar
734 WVPASS attr -s foo -V bar "$testfs"/src/foo
735 WVPASS attr -s foo -V bar "$testfs"/src/bar
736 (WVPASS cd "$testfs"; WVPASS test-src-create-extract) || exit $?
738 # Test restoration to a limited filesystem (vfat).
740 WVPASS bup meta --create --recurse --file "$testfs"/src.meta \
742 WVPASS force-delete "$testfs_limited"/src-restore
743 WVPASS mkdir "$testfs_limited"/src-restore
744 WVPASS cd "$testfs_limited"/src-restore
745 WVFAIL bup meta --extract --file "$testfs"/src.meta
746 WVFAIL bup meta --extract --file "$testfs"/src.meta 2>&1 \
747 | WVPASS grep -e "^xattr\.set u\?'" \
748 | WVPASS bup-cfg-py -c \
749 'import sys; exit(not len(sys.stdin.readlines()) == 2)'
752 WVSTART 'meta - POSIX.1e ACLs (as root)'
753 WVPASS force-delete "$testfs"/src
754 WVPASS mkdir "$testfs"/src
755 WVPASS touch "$testfs"/src/foo
756 WVPASS mkdir "$testfs"/src/bar
757 WVPASS setfacl -m u:root:r "$testfs"/src/foo
758 WVPASS setfacl -m u:root:r "$testfs"/src/bar
759 (WVPASS cd "$testfs"; WVPASS test-src-create-extract) || exit $?
761 # Test restoration to a limited filesystem (vfat).
763 WVPASS bup meta --create --recurse --file "$testfs"/src.meta \
765 WVPASS force-delete "$testfs_limited"/src-restore
766 WVPASS mkdir "$testfs_limited"/src-restore
767 WVPASS cd "$testfs_limited"/src-restore
768 WVFAIL bup meta --extract --file "$testfs"/src.meta 2>&1 \
769 | WVPASS grep -e '^POSIX1e ACL applyto:' \
770 | WVPASS bup-cfg-py -c \
771 'import sys; exit(not len(sys.stdin.readlines()) == 2)'
774 WVPASS umount "$testfs"
775 WVPASS umount "$testfs_limited"
776 WVPASS rm -r "$testfs" "$testfs_limited"
778 WVPASS rm -r "$tmpdir"
783 WVPASS rm -r "$tmpdir"