2 . wvtest-bup.sh || exit $?
7 root_status="$(t/root-status)" || exit $?
9 TOP="$(WVPASS pwd)" || exit $?
10 tmpdir="$(WVPASS wvmktempdir)" || exit $?
12 export BUP_DIR="$tmpdir/bup"
14 WVPASS force-delete "$TOP/bupmeta.tmp"
15 timestamp_resolutions="$(t/ns-timestamp-resolutions "$TOP/bupmeta.tmp")" \
17 WVPASS rm "$TOP/bupmeta.tmp"
18 atime_resolution="$(echo $timestamp_resolutions | WVPASS cut -d' ' -f 1)" \
20 mtime_resolution="$(echo $timestamp_resolutions | WVPASS cut -d' ' -f 2)" \
30 "$TOP/t/hardlink-sets" "$@"
35 "$TOP/t/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:$PATH" # pick up bup
48 # Skip atime (test elsewhere) to avoid the observer effect.
49 WVPASS find . | WVPASS sort \
50 | WVPASS xargs bup xstat \
51 --mtime-resolution "$mtime_resolution"ns \
52 --exclude-fields ctime,atime,size
56 test-src-create-extract()
58 # Test bup meta create/extract for ./src -> ./src-restore.
59 # Also writes to ./src-stat and ./src-restore-stat.
61 (WVPASS cd src; WVPASS genstat) > src-stat || exit $?
62 WVPASS bup meta --create --recurse --file src.meta src
64 WVPASS force-delete src-restore
65 WVPASS mkdir src-restore
67 WVPASS bup meta --extract --file ../src.meta
69 (WVPASS cd src; WVPASS genstat >../../src-restore-stat) || exit $?
70 WVPASS diff -U5 ../src-stat ../src-restore-stat
71 # Test start/finish extract.
72 WVPASS force-delete src
73 WVPASS bup meta --start-extract --file ../src.meta
75 WVPASS bup meta --finish-extract --file ../src.meta
76 (WVPASS cd src; WVPASS genstat >../../src-restore-stat) || exit $?
77 WVPASS diff -U5 ../src-stat ../src-restore-stat
81 test-src-save-restore()
83 # Test bup save/restore metadata for ./src -> ./src-restore. Also
84 # writes to ./src.bup. Note that for now this just tests the
85 # restore below src/, in order to avoid having to worry about
86 # operations that require root (like chown /home).
90 export BUP_DIR=$(pwd)/src.bup || exit $?
93 WVPASS bup save -t -n src src
95 WVPASS force-delete src-restore
96 WVPASS mkdir src-restore
97 WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
98 WVPASS test -d src-restore/src
99 WVPASS "$TOP/t/compare-trees" -c src/ src-restore/src/
100 WVPASS rm -rf src.bup
106 WVPASS force-delete "$BUP_DIR"
107 WVPASS force-delete "$TOP/bupmeta.tmp"
108 WVPASS mkdir -p "$TOP/bupmeta.tmp/src"
109 WVPASS cp -pPR Documentation cmd config lib "$TOP/bupmeta.tmp"/src
111 # Add some hard links for the general tests.
113 WVPASS cd "$TOP/bupmeta.tmp"/src
114 WVPASS touch hardlink-target
115 WVPASS ln hardlink-target hardlink-1
116 WVPASS ln hardlink-target hardlink-2
117 WVPASS ln hardlink-target hardlink-3
120 # Add some trivial files for the index, modify, save tests.
122 WVPASS cd "$TOP/bupmeta.tmp"/src
123 WVPASS mkdir volatile
124 WVPASS touch volatile/{1,2,3}
127 # Regression test for metadata sort order. Previously, these two
128 # entries would sort in the wrong order because the metadata
129 # entries were being sorted by mangled name, but the index isn't.
130 WVPASS dd if=/dev/zero of="$TOP/bupmeta.tmp"/src/foo bs=1k count=33
131 WVPASS touch -t 201111111111 "$TOP/bupmeta.tmp"/src/foo
132 WVPASS touch -t 201112121111 "$TOP/bupmeta.tmp"/src/foo-bar
134 t/mksock "$TOP/bupmeta.tmp/src/test-socket" || true
137 # Use the test tree to check bup meta.
138 WVSTART 'meta --create/--extract'
140 WVPASS setup-test-tree
141 WVPASS cd "$TOP/bupmeta.tmp"
142 WVPASS test-src-create-extract
144 # Test a top-level file (not dir).
145 WVPASS touch src-file
146 WVPASS bup meta -cf src-file.meta src-file
149 WVPASS bup meta -xf ../src-file.meta
152 # Use the test tree to check bup save/restore metadata.
153 WVSTART 'metadata save/restore (general)'
155 WVPASS setup-test-tree
156 WVPASS cd "$TOP/bupmeta.tmp"
157 WVPASS test-src-save-restore
159 # Test a deeper subdir/ to make sure top-level non-dir metadata is
160 # restored correctly. We need at least one dir and one non-dir at
162 WVPASS test -f src/lib/__init__.py
163 WVPASS test -d src/lib/bup
164 WVPASS rm -rf src.bup
166 export BUP_DIR=$(pwd)/src.bup || exit $?
168 WVPASS touch -t 201111111111 src-restore # Make sure the top won't match.
170 WVPASS bup save -t -n src src
171 WVPASS force-delete src-restore
172 WVPASS bup restore -C src-restore "/src/latest$(pwd)/src/lib/"
173 WVPASS touch -t 201211111111 src-restore # Make sure the top won't match.
174 # Check that the only difference is the top dir.
175 WVFAIL $TOP/t/compare-trees -c src/lib/ src-restore/ > tmp-compare-trees
176 WVPASSEQ $(cat tmp-compare-trees | wc -l) 2
177 WVPASS tail -n +2 tmp-compare-trees | WVPASS grep -qE '^\.d[^ ]+ \./$'
180 # Test that we pull the index (not filesystem) metadata for any
181 # unchanged files whenever we're saving other files in a given
183 WVSTART 'metadata save/restore (using index metadata)'
185 WVPASS setup-test-tree
186 WVPASS cd "$TOP/bupmeta.tmp"
188 # ...for now -- might be a problem with hardlink restores that was
189 # causing noise wrt this test.
190 WVPASS rm -rf src/hardlink*
192 # Pause here to keep the filesystem changes far enough away from
193 # the first index run that bup won't cap their index timestamps
194 # (see "bup help index" for more information). Without this
195 # sleep, the compare-trees test below "Bup should *not* pick up
196 # these metadata..." may fail.
199 WVPASS rm -rf src.bup
201 export BUP_DIR=$(pwd)/src.bup || exit $?
204 WVPASS bup save -t -n src src
206 WVPASS force-delete src-restore-1
207 WVPASS mkdir src-restore-1
208 WVPASS bup restore -C src-restore-1 "/src/latest$(pwd)/"
209 WVPASS test -d src-restore-1/src
210 WVPASS "$TOP/t/compare-trees" -c src/ src-restore-1/src/
212 WVPASS echo "blarg" > src/volatile/1
213 WVPASS cp -a src/volatile/1 src-restore-1/src/volatile/
216 # Bup should *not* pick up these metadata changes.
217 WVPASS touch src/volatile/2
219 WVPASS bup save -t -n src src
221 WVPASS force-delete src-restore-2
222 WVPASS mkdir src-restore-2
223 WVPASS bup restore -C src-restore-2 "/src/latest$(pwd)/"
224 WVPASS test -d src-restore-2/src
225 WVPASS "$TOP/t/compare-trees" -c src-restore-1/src/ src-restore-2/src/
227 WVPASS rm -rf src.bup
230 setup-hardlink-test()
232 WVPASS rm -rf "$TOP/bupmeta.tmp"/src "$TOP/bupmeta.tmp"/src.bup
233 WVPASS mkdir "$TOP/bupmeta.tmp"/src "$TOP/bupmeta.tmp"/src.bup
237 hardlink-test-run-restore()
239 WVPASS force-delete src-restore
240 WVPASS mkdir src-restore
241 WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
242 WVPASS test -d src-restore/src
245 # Test hardlinks more carefully.
246 WVSTART 'metadata save/restore (hardlinks)'
248 export BUP_DIR="$TOP/bupmeta.tmp/src.bup"
249 WVPASS force-delete "$TOP/bupmeta.tmp"
250 WVPASS mkdir -p "$TOP/bupmeta.tmp"
252 WVPASS cd "$TOP/bupmeta.tmp"
254 # Test trivial case - single hardlink.
255 WVPASS setup-hardlink-test
257 WVPASS cd "$TOP/bupmeta.tmp"/src
258 WVPASS touch hardlink-target
259 WVPASS ln hardlink-target hardlink-1
262 WVPASS bup save -t -n src src
263 WVPASS hardlink-test-run-restore
264 WVPASS "$TOP/t/compare-trees" -c src/ src-restore/src/
266 # Test the case where the hardlink hasn't changed, but the tree
267 # needs to be saved again. i.e. the save-cmd.py "if hashvalid:"
270 WVPASS cd "$TOP/bupmeta.tmp"/src
271 WVPASS echo whatever > something-new
274 WVPASS bup save -t -n src src
275 WVPASS hardlink-test-run-restore
276 WVPASS "$TOP/t/compare-trees" -c src/ src-restore/src/
278 # Test hardlink changes between index runs.
280 WVPASS setup-hardlink-test
281 WVPASS cd "$TOP/bupmeta.tmp"/src
282 WVPASS touch hardlink-target-a
283 WVPASS touch hardlink-target-b
284 WVPASS ln hardlink-target-a hardlink-b-1
285 WVPASS ln hardlink-target-a hardlink-a-1
287 WVPASS bup index -vv src
288 WVPASS rm src/hardlink-b-1
289 WVPASS ln src/hardlink-target-b src/hardlink-b-1
290 WVPASS bup index -vv src
291 WVPASS bup save -t -n src src
292 WVPASS hardlink-test-run-restore
293 WVPASS echo ./src/hardlink-a-1 > hardlink-sets.expected
294 WVPASS echo ./src/hardlink-target-a >> hardlink-sets.expected
295 WVPASS echo >> hardlink-sets.expected
296 WVPASS echo ./src/hardlink-b-1 >> hardlink-sets.expected
297 WVPASS echo ./src/hardlink-target-b >> hardlink-sets.expected
298 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
300 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
302 # Test hardlink changes between index and save -- hardlink set [a
303 # b c d] changes to [a b] [c d]. At least right now bup should
304 # notice and recreate the latter.
305 WVPASS setup-hardlink-test
306 WVPASS cd "$TOP/bupmeta.tmp"/src
312 WVPASS bup index -vv src
313 WVPASS rm src/c src/d
315 WVPASS ln src/c src/d
316 WVPASS bup save -t -n src src
317 WVPASS hardlink-test-run-restore
318 WVPASS echo ./src/a > hardlink-sets.expected
319 WVPASS echo ./src/b >> hardlink-sets.expected
320 WVPASS echo >> hardlink-sets.expected
321 WVPASS echo ./src/c >> hardlink-sets.expected
322 WVPASS echo ./src/d >> hardlink-sets.expected
323 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
325 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
327 # Test that we don't link outside restore tree.
328 WVPASS setup-hardlink-test
329 WVPASS cd "$TOP/bupmeta.tmp"
330 WVPASS mkdir src/a src/b
332 WVPASS ln src/a/1 src/b/1
333 WVPASS bup index -vv src
334 WVPASS bup save -t -n src src
335 WVPASS force-delete src-restore
336 WVPASS mkdir src-restore
337 WVPASS bup restore -C src-restore "/src/latest$(pwd)/src/a/"
338 WVPASS test -e src-restore/1
339 WVPASS echo -n > hardlink-sets.expected
340 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
342 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
344 # Test that we do link within separate sub-trees.
345 WVPASS setup-hardlink-test
346 WVPASS cd "$TOP/bupmeta.tmp"
347 WVPASS mkdir src/a src/b
349 WVPASS ln src/a/1 src/b/1
350 WVPASS bup index -vv src/a src/b
351 WVPASS bup save -t -n src src/a src/b
352 WVPASS hardlink-test-run-restore
353 WVPASS echo ./src/a/1 > hardlink-sets.expected
354 WVPASS echo ./src/b/1 >> hardlink-sets.expected
355 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
357 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
360 WVSTART 'meta --edit'
362 WVPASS force-delete "$TOP/bupmeta.tmp"
363 WVPASS mkdir "$TOP/bupmeta.tmp"
364 WVPASS cd "$TOP/bupmeta.tmp"
366 WVPASS bup meta -cf src.meta src
368 WVPASS bup meta --edit --set-uid 0 src.meta | WVPASS bup meta -tvvf - \
369 | WVPASS grep -qE '^uid: 0'
370 WVPASS bup meta --edit --set-uid 1000 src.meta | WVPASS bup meta -tvvf - \
371 | WVPASS grep -qE '^uid: 1000'
373 WVPASS bup meta --edit --set-gid 0 src.meta | WVPASS bup meta -tvvf - \
374 | WVPASS grep -qE '^gid: 0'
375 WVPASS bup meta --edit --set-gid 1000 src.meta | WVPASS bup meta -tvvf - \
376 | WVPASS grep -qE '^gid: 1000'
378 WVPASS bup meta --edit --set-user foo src.meta | WVPASS bup meta -tvvf - \
379 | WVPASS grep -qE '^user: foo'
380 WVPASS bup meta --edit --set-user bar src.meta | WVPASS bup meta -tvvf - \
381 | WVPASS grep -qE '^user: bar'
382 WVPASS bup meta --edit --unset-user src.meta | WVPASS bup meta -tvvf - \
383 | WVPASS grep -qE '^user:'
384 WVPASS bup meta --edit --set-user bar --unset-user src.meta \
385 | WVPASS bup meta -tvvf - | WVPASS grep -qE '^user:'
386 WVPASS bup meta --edit --unset-user --set-user bar src.meta \
387 | WVPASS bup meta -tvvf - | WVPASS grep -qE '^user: bar'
389 WVPASS bup meta --edit --set-group foo src.meta | WVPASS bup meta -tvvf - \
390 | WVPASS grep -qE '^group: foo'
391 WVPASS bup meta --edit --set-group bar src.meta | WVPASS bup meta -tvvf - \
392 | WVPASS grep -qE '^group: bar'
393 WVPASS bup meta --edit --unset-group src.meta | WVPASS bup meta -tvvf - \
394 | WVPASS grep -qE '^group:'
395 WVPASS bup meta --edit --set-group bar --unset-group src.meta \
396 | WVPASS bup meta -tvvf - | WVPASS grep -qE '^group:'
397 WVPASS bup meta --edit --unset-group --set-group bar src.meta \
398 | WVPASS bup meta -tvvf - | grep -qE '^group: bar'
401 WVSTART 'meta --no-recurse'
404 WVPASS force-delete "$TOP/bupmeta.tmp"
405 WVPASS mkdir "$TOP/bupmeta.tmp"
406 WVPASS cd "$TOP/bupmeta.tmp"
409 WVPASS touch src/foo/{1,2,3}
410 WVPASS bup meta -cf src.meta src
411 WVPASSEQ "$(LC_ALL=C; bup meta -tf src.meta | sort)" "src/
416 WVPASS bup meta --no-recurse -cf src.meta src
417 WVPASSEQ "$(LC_ALL=C; bup meta -tf src.meta | sort)" "src/"
420 # Test ownership restoration (when not root or fakeroot).
422 if [ "$root_status" != none ]; then
426 first_group="$(WVPASS python -c 'import os,grp; \
427 print grp.getgrgid(os.getgroups()[0])[0]')" || exit $?
428 last_group="$(python -c 'import os,grp; \
429 print grp.getgrgid(os.getgroups()[-1])[0]')" || exit $?
430 last_group_erx="$(escape-erx "$last_group")"
432 WVSTART 'metadata (restoration of ownership)'
433 WVPASS force-delete "$TOP/bupmeta.tmp"
434 WVPASS mkdir "$TOP/bupmeta.tmp"
435 WVPASS cd "$TOP/bupmeta.tmp"
437 # Some systems always assign the parent dir group to new paths
438 # (sgid). Make sure the group is one we're in.
439 WVPASS chgrp -R "$first_group" src
441 WVPASS bup meta -cf src.meta src
445 # Make sure we don't change (or try to change) the user when not root.
446 WVPASS bup meta --edit --set-user root ../src.meta | WVPASS bup meta -x
447 WVPASS bup xstat src | WVPASS grep -qvE '^user: root'
449 WVPASS bup meta --edit --unset-user --set-uid 0 ../src.meta \
451 WVPASS bup xstat src | WVPASS grep -qvE '^user: root'
453 # Make sure we can restore one of the user's groups.
455 WVPASS bup meta --edit --set-group "$last_group" ../src.meta \
457 WVPASS bup xstat src | WVPASS grep -qE "^group: $last_group_erx"
459 # Make sure we can restore one of the user's gids.
460 user_gids="$(id -G)" || exit $?
461 last_gid="$(echo ${user_gids/* /})" || exit $?
463 WVPASS bup meta --edit --unset-group --set-gid "$last_gid" ../src.meta \
465 WVPASS bup xstat src | WVPASS grep -qE "^gid: $last_gid"
467 # Test --numeric-ids (gid).
469 current_gidx=$(bup meta -tvvf ../src.meta | grep -e '^gid:') || exit $?
470 WVPASS bup meta --edit --set-group "$last_group" ../src.meta \
471 | WVPASS bup meta -x --numeric-ids
472 new_gidx=$(bup xstat src | grep -e '^gid:') || exit $?
473 WVPASSEQ "$current_gidx" "$new_gidx"
475 # Test that restoring an unknown user works.
476 unknown_user=$("$TOP"/t/unknown-owner --user) || exit $?
478 current_uidx=$(bup meta -tvvf ../src.meta | grep -e '^uid:') || exit $?
479 WVPASS bup meta --edit --set-user "$unknown_user" ../src.meta \
481 new_uidx=$(bup xstat src | grep -e '^uid:') || exit $?
482 WVPASSEQ "$current_uidx" "$new_uidx"
484 # Test that restoring an unknown group works.
485 unknown_group=$("$TOP"/t/unknown-owner --group) || exit $?
487 current_gidx=$(bup meta -tvvf ../src.meta | grep -e '^gid:') || exit $?
488 WVPASS bup meta --edit --set-group "$unknown_group" ../src.meta \
490 new_gidx=$(bup xstat src | grep -e '^gid:') || exit $?
491 WVPASSEQ "$current_gidx" "$new_gidx"
494 # Test ownership restoration (when root or fakeroot).
496 if [ "$root_status" = none ]; then
500 uid=$(WVPASS id -un) || exit $?
501 gid=$(WVPASS id -gn) || exit $?
503 WVSTART 'metadata (restoration of ownership as root)'
504 WVPASS force-delete "$TOP/bupmeta.tmp"
505 WVPASS mkdir "$TOP/bupmeta.tmp"
506 WVPASS cd "$TOP/bupmeta.tmp"
508 WVPASS chown "$uid:$gid" src # In case the parent dir is sgid, etc.
509 WVPASS bup meta -cf src.meta src
512 WVPASS chmod 700 dest # so we can't accidentally do something insecure
515 other_uinfo="$(id-other-than --user "$uid")" || exit $?
516 other_user="${other_uinfo%%:*}"
517 other_uid="${other_uinfo##*:}"
519 other_ginfo="$(id-other-than --group "$gid")" || exit $?
520 other_group="${other_ginfo%%:*}"
521 other_gid="${other_ginfo##*:}"
523 # Make sure we can restore a uid (must be in /etc/passwd b/c cygwin).
524 WVPASS bup meta --edit --unset-user --set-uid "$other_uid" ../src.meta \
526 WVPASS bup xstat src | WVPASS grep -qE "^uid: $other_uid"
528 # Make sure we can restore a gid (must be in /etc/group b/c cygwin).
529 WVPASS bup meta --edit --unset-group --set-gid "$other_gid" ../src.meta \
531 WVPASS bup xstat src | WVPASS grep -qE "^gid: $other_gid"
533 other_uinfo2="$(id-other-than --user "$(id -un)" "$other_user")" || exit $?
534 other_user2="${other_uinfo2%%:*}"
535 other_user2_erx="$(escape-erx "$other_user2")" || exit $?
536 other_uid2="${other_uinfo2##*:}"
538 other_ginfo2="$(id-other-than --group "$(id -gn)" "$other_group")" || exit $?
539 other_group2="${other_ginfo2%%:*}"
540 other_group2_erx="$(escape-erx "$other_group2")" || exit $?
541 other_gid2="${other_ginfo2##*:}"
543 # Try to restore a user (and see that user trumps uid when uid is not 0).
544 WVPASS bup meta --edit \
545 --set-uid "$other_uid" --set-user "$other_user2" ../src.meta \
547 WVPASS bup xstat src | WVPASS grep -qE "^user: $other_user2_erx"
549 # Try to restore a group (and see that group trumps gid when gid is not 0).
550 WVPASS bup meta --edit \
551 --set-gid "$other_gid" --set-group "$other_group2" ../src.meta \
553 WVPASS bup xstat src | WVPASS grep -qE "^group: $other_group2_erx"
555 # Test --numeric-ids (uid). Note the name 'root' is not handled
556 # specially, so we use that here as the test user name. We assume
557 # that the root user's uid is never 42.
559 WVPASS bup meta --edit --set-user root --set-uid "$other_uid" ../src.meta \
560 | WVPASS bup meta -x --numeric-ids
561 new_uidx=$(bup xstat src | grep -e '^uid:') || exit $?
562 WVPASSEQ "$new_uidx" "uid: $other_uid"
564 # Test --numeric-ids (gid). Note the name 'root' is not handled
565 # specially, so we use that here as the test group name. We
566 # assume that the root group's gid is never 42.
568 WVPASS bup meta --edit --set-group root --set-gid "$other_gid" ../src.meta \
569 | WVPASS bup meta -x --numeric-ids
570 new_gidx=$(bup xstat src | grep -e '^gid:') || exit $?
571 WVPASSEQ "$new_gidx" "gid: $other_gid"
573 # Test that restoring an unknown user works.
574 unknown_user=$("$TOP"/t/unknown-owner --user) || exit $?
576 WVPASS bup meta --edit \
577 --set-uid "$other_uid" --set-user "$unknown_user" ../src.meta \
579 new_uidx=$(bup xstat src | grep -e '^uid:') || exit $?
580 WVPASSEQ "$new_uidx" "uid: $other_uid"
582 # Test that restoring an unknown group works.
583 unknown_group=$("$TOP"/t/unknown-owner --group) || exit $?
585 WVPASS bup meta --edit \
586 --set-gid "$other_gid" --set-group "$unknown_group" ../src.meta \
588 new_gidx=$(bup xstat src | grep -e '^gid:') || exit $?
589 WVPASSEQ "$new_gidx" "gid: $other_gid"
591 if ! [[ $(uname) =~ CYGWIN ]]; then
592 # For now, skip these on Cygwin because it doesn't allow
593 # restoring an unknown uid/gid.
595 # Make sure a uid of 0 trumps a non-root user.
596 WVPASS bup meta --edit --set-user "$other_user2" ../src.meta \
598 WVPASS bup xstat src | WVPASS grep -qvE "^user: $other_user2_erx"
599 WVPASS bup xstat src | WVPASS grep -qE "^uid: 0"
601 # Make sure a gid of 0 trumps a non-root group.
602 WVPASS bup meta --edit --set-group "$other_group2" ../src.meta \
604 WVPASS bup xstat src | WVPASS grep -qvE "^group: $other_group2_erx"
605 WVPASS bup xstat src | WVPASS grep -qE "^gid: 0"
610 # Root-only tests that require an FS with all the trimmings: ACLs,
611 # Linux attr, Linux xattr, etc.
612 if [ "$root_status" = root ]; then
614 # Some cleanup handled in universal-cleanup() above.
615 # These tests are only likely to work under Linux for now
617 [[ $(uname) =~ Linux ]] || exit 0
619 if ! modprobe loop; then
620 echo 'Unable to load loopback module; skipping dependent tests.' 1>&2
624 testfs="$(WVPASS wvmkmountpt)" || exit $?
625 testfs_limited="$(WVPASS wvmkmountpt)" || exit $?
627 WVSTART 'meta - general (as root)'
628 WVPASS setup-test-tree
629 WVPASS cd "$TOP/bupmeta.tmp"
632 WVPASS dd if=/dev/zero of=testfs.img bs=1M count=32
633 # Make sure we have all the options the chattr test needs
634 # (i.e. create a "normal" ext4 filesystem).
635 WVPASS mke2fs -F -m 0 \
637 -O has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize \
639 WVPASS mount -o loop,acl,user_xattr testfs.img "$testfs"
640 # Hide, so that tests can't create risks.
641 WVPASS chown root:root "$testfs"
642 WVPASS chmod 0700 "$testfs"
644 umount "$testfs_limited"
645 WVPASS dd if=/dev/zero of=testfs-limited.img bs=1M count=32
646 WVPASS mkfs -t vfat testfs-limited.img
647 WVPASS mount -o loop,uid=root,gid=root,umask=0077 \
648 testfs-limited.img "$testfs_limited"
650 WVPASS cp -pPR src "$testfs"/src
651 (WVPASS cd "$testfs"; WVPASS test-src-create-extract) || exit $?
653 WVSTART 'meta - atime (as root)'
654 WVPASS force-delete "$testfs"/src
655 WVPASS mkdir "$testfs"/src
657 WVPASS mkdir "$testfs"/src/foo
658 WVPASS touch "$testfs"/src/bar
659 PYTHONPATH="$TOP/lib" \
660 WVPASS python -c "from bup import xstat; \
661 x = xstat.timespec_to_nsecs((42, 0));\
662 xstat.utime('$testfs/src/foo', (x, x));\
663 xstat.utime('$testfs/src/bar', (x, x));"
665 WVPASS bup meta -v --create --recurse --file src.meta src
666 WVPASS bup meta -tvf src.meta
668 WVPASS force-delete src-restore
669 WVPASS mkdir src-restore
670 WVPASS cd src-restore
671 WVPASS bup meta --extract --file ../src.meta
672 WVPASSEQ "$(bup xstat --include-fields=atime src/foo)" "atime: 42"
673 WVPASSEQ "$(bup xstat --include-fields=atime src/bar)" "atime: 42"
674 # Test start/finish extract.
675 WVPASS force-delete src
676 WVPASS bup meta --start-extract --file ../src.meta
678 WVPASS bup meta --finish-extract --file ../src.meta
679 WVPASSEQ "$(bup xstat --include-fields=atime src/foo)" "atime: 42"
680 WVPASSEQ "$(bup xstat --include-fields=atime src/bar)" "atime: 42"
683 WVSTART 'meta - Linux attr (as root)'
684 WVPASS force-delete "$testfs"/src
685 WVPASS mkdir "$testfs"/src
687 WVPASS touch "$testfs"/src/foo
688 WVPASS mkdir "$testfs"/src/bar
689 WVPASS chattr +acdeijstuADST "$testfs"/src/foo
690 WVPASS chattr +acdeijstuADST "$testfs"/src/bar
691 (WVPASS cd "$testfs"; WVPASS test-src-create-extract) || exit $?
692 # Test restoration to a limited filesystem (vfat).
694 WVPASS bup meta --create --recurse --file "$testfs"/src.meta \
696 WVPASS force-delete "$testfs_limited"/src-restore
697 WVPASS mkdir "$testfs_limited"/src-restore
698 WVPASS cd "$testfs_limited"/src-restore
699 WVFAIL bup meta --extract --file "$testfs"/src.meta 2>&1 \
700 | WVPASS grep -e '^Linux chattr:' \
702 'import sys; exit(not len(sys.stdin.readlines()) == 3)'
706 WVSTART 'meta - Linux xattr (as root)'
707 WVPASS force-delete "$testfs"/src
708 WVPASS mkdir "$testfs"/src
709 WVPASS touch "$testfs"/src/foo
710 WVPASS mkdir "$testfs"/src/bar
711 WVPASS attr -s foo -V bar "$testfs"/src/foo
712 WVPASS attr -s foo -V bar "$testfs"/src/bar
713 (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
723 WVFAIL bup meta --extract --file "$testfs"/src.meta 2>&1 \
724 | WVPASS grep -e "^xattr\.set '" \
726 'import sys; exit(not len(sys.stdin.readlines()) == 2)'
729 WVSTART 'meta - POSIX.1e ACLs (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 setfacl -m u:root:r "$testfs"/src/foo
735 WVPASS setfacl -m u:root:r "$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 2>&1 \
746 | WVPASS grep -e '^POSIX1e ACL applyto:' \
748 'import sys; exit(not len(sys.stdin.readlines()) == 2)'
751 WVPASS umount "$testfs"
752 WVPASS umount "$testfs_limited"
753 WVPASS rm -r "$testfs" "$testfs_limited"
758 WVPASS rm -r "$tmpdir"