7 TOP="$(WVPASS pwd)" || exit $?
8 export BUP_DIR="$TOP/buptest.tmp"
10 WVPASS force-delete "$TOP/bupmeta.tmp"
11 timestamp_resolutions="$(t/ns-timestamp-resolutions "$TOP/bupmeta.tmp")" \
13 WVPASS rm "$TOP/bupmeta.tmp"
14 atime_resolution="$(echo $timestamp_resolutions | WVPASS cut -d' ' -f 1)" \
16 mtime_resolution="$(echo $timestamp_resolutions | WVPASS cut -d' ' -f 2)" \
26 "$TOP/t/hardlink-sets" "$@"
31 "$TOP/t/id-other-than" "$@"
34 # Very simple metadata tests -- create a test tree then check that bup
35 # meta can reproduce the metadata correctly (according to bup xstat)
36 # via create, extract, start-extract, and finish-extract. The current
37 # tests are crude, and this does not fully test devices, varying
38 # users/groups, acls, attrs, etc.
43 export PATH="$TOP:$PATH" # pick up bup
44 # Skip atime (test elsewhere) to avoid the observer effect.
45 WVPASS find . | WVPASS sort \
46 | WVPASS xargs bup xstat \
47 --mtime-resolution "$mtime_resolution"ns \
48 --exclude-fields ctime,atime,size
52 test-src-create-extract()
54 # Test bup meta create/extract for ./src -> ./src-restore.
55 # Also writes to ./src-stat and ./src-restore-stat.
57 (WVPASS cd src; WVPASS genstat) > src-stat || exit $?
58 WVPASS bup meta --create --recurse --file src.meta src
60 WVPASS force-delete src-restore
61 WVPASS mkdir src-restore
63 WVPASS bup meta --extract --file ../src.meta
65 (WVPASS cd src; WVPASS genstat >../../src-restore-stat) || exit $?
66 WVPASS diff -U5 ../src-stat ../src-restore-stat
67 # Test start/finish extract.
68 WVPASS force-delete src
69 WVPASS bup meta --start-extract --file ../src.meta
71 WVPASS bup meta --finish-extract --file ../src.meta
72 (WVPASS cd src; WVPASS genstat >../../src-restore-stat) || exit $?
73 WVPASS diff -U5 ../src-stat ../src-restore-stat
77 test-src-save-restore()
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).
86 export BUP_DIR=$(pwd)/src.bup
89 WVPASS bup save -t -n src src
91 WVPASS force-delete src-restore
92 WVPASS mkdir src-restore
93 WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
94 WVPASS test -d src-restore/src
95 WVPASS "$TOP/t/compare-trees" -c src/ src-restore/src/
102 if [ $(t/root-status) != root ]; then return 0; fi
103 umount "$TOP/bupmeta.tmp/testfs" || true
104 umount "$TOP/bupmeta.tmp/testfs-limited" || true
107 WVPASS universal-cleanup
108 trap universal-cleanup EXIT
112 WVPASS force-delete "$BUP_DIR"
113 WVPASS force-delete "$TOP/bupmeta.tmp"
114 WVPASS mkdir -p "$TOP/bupmeta.tmp/src"
115 WVPASS cp -pPR Documentation cmd config lib "$TOP/bupmeta.tmp"/src
117 # Add some hard links for the general tests.
119 WVPASS cd "$TOP/bupmeta.tmp"/src
120 WVPASS touch hardlink-target
121 WVPASS ln hardlink-target hardlink-1
122 WVPASS ln hardlink-target hardlink-2
123 WVPASS ln hardlink-target hardlink-3
126 # Add some trivial files for the index, modify, save tests.
128 WVPASS cd "$TOP/bupmeta.tmp"/src
129 WVPASS mkdir volatile
130 WVPASS touch volatile/{1,2,3}
133 # Regression test for metadata sort order. Previously, these two
134 # entries would sort in the wrong order because the metadata
135 # entries were being sorted by mangled name, but the index isn't.
136 WVPASS dd if=/dev/zero of="$TOP/bupmeta.tmp"/src/foo bs=1k count=33
137 WVPASS touch -t 201111111111 "$TOP/bupmeta.tmp"/src/foo
138 WVPASS touch -t 201112121111 "$TOP/bupmeta.tmp"/src/foo-bar
140 t/mksock "$TOP/bupmeta.tmp/src/test-socket" || true
143 # Use the test tree to check bup meta.
144 WVSTART 'meta --create/--extract'
146 WVPASS setup-test-tree
147 WVPASS cd "$TOP/bupmeta.tmp"
148 WVPASS test-src-create-extract
150 # Test a top-level file (not dir).
151 WVPASS touch src-file
152 WVPASS bup meta -cf src-file.meta src-file
155 WVPASS bup meta -xf ../src-file.meta
158 # Use the test tree to check bup save/restore metadata.
159 WVSTART 'metadata save/restore (general)'
161 WVPASS setup-test-tree
162 WVPASS cd "$TOP/bupmeta.tmp"
163 WVPASS test-src-save-restore
165 # Test a deeper subdir/ to make sure top-level non-dir metadata is
166 # restored correctly. We need at least one dir and one non-dir at
168 WVPASS test -f src/lib/__init__.py
169 WVPASS test -d src/lib/bup
170 WVPASS rm -rf src.bup
172 export BUP_DIR=$(pwd)/src.bup
174 WVPASS touch -t 201111111111 src-restore # Make sure the top won't match.
176 WVPASS bup save -t -n src src
177 WVPASS force-delete src-restore
178 WVPASS bup restore -C src-restore "/src/latest$(pwd)/src/lib/"
179 WVPASS touch -t 201211111111 src-restore # Make sure the top won't match.
180 # Check that the only difference is the top dir.
181 WVFAIL $TOP/t/compare-trees -c src/lib/ src-restore/ > tmp-compare-trees
182 WVPASSEQ $(cat tmp-compare-trees | wc -l) 2
183 WVPASS tail -n +2 tmp-compare-trees | WVPASS grep -qE '^\.d[^ ]+ \./$'
186 # Test that we pull the index (not filesystem) metadata for any
187 # unchanged files whenever we're saving other files in a given
189 WVSTART 'metadata save/restore (using index metadata)'
191 WVPASS setup-test-tree
192 WVPASS cd "$TOP/bupmeta.tmp"
194 # ...for now -- might be a problem with hardlink restores that was
195 # causing noise wrt this test.
196 WVPASS rm -rf src/hardlink*
198 # Pause here to keep the filesystem changes far enough away from
199 # the first index run that bup won't cap their index timestamps
200 # (see "bup help index" for more information). Without this
201 # sleep, the compare-trees test below "Bup should *not* pick up
202 # these metadata..." may fail.
205 WVPASS rm -rf src.bup
207 export BUP_DIR=$(pwd)/src.bup
210 WVPASS bup save -t -n src src
212 WVPASS force-delete src-restore-1
213 WVPASS mkdir src-restore-1
214 WVPASS bup restore -C src-restore-1 "/src/latest$(pwd)/"
215 WVPASS test -d src-restore-1/src
216 WVPASS "$TOP/t/compare-trees" -c src/ src-restore-1/src/
218 WVPASS echo "blarg" > src/volatile/1
219 WVPASS cp -a src/volatile/1 src-restore-1/src/volatile/
222 # Bup should *not* pick up these metadata changes.
223 WVPASS touch src/volatile/2
225 WVPASS bup save -t -n src src
227 WVPASS force-delete src-restore-2
228 WVPASS mkdir src-restore-2
229 WVPASS bup restore -C src-restore-2 "/src/latest$(pwd)/"
230 WVPASS test -d src-restore-2/src
231 WVPASS "$TOP/t/compare-trees" -c src-restore-1/src/ src-restore-2/src/
233 WVPASS rm -rf src.bup
236 setup-hardlink-test()
238 WVPASS rm -rf "$TOP/bupmeta.tmp"/src "$TOP/bupmeta.tmp"/src.bup
239 WVPASS mkdir "$TOP/bupmeta.tmp"/src "$TOP/bupmeta.tmp"/src.bup
243 hardlink-test-run-restore()
245 WVPASS force-delete src-restore
246 WVPASS mkdir src-restore
247 WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
248 WVPASS test -d src-restore/src
251 # Test hardlinks more carefully.
252 WVSTART 'metadata save/restore (hardlinks)'
254 export BUP_DIR="$TOP/bupmeta.tmp/src.bup"
255 WVPASS force-delete "$TOP/bupmeta.tmp"
256 WVPASS mkdir -p "$TOP/bupmeta.tmp"
258 WVPASS cd "$TOP/bupmeta.tmp"
260 # Test trivial case - single hardlink.
261 WVPASS setup-hardlink-test
263 WVPASS cd "$TOP/bupmeta.tmp"/src
264 WVPASS touch hardlink-target
265 WVPASS ln hardlink-target hardlink-1
268 WVPASS bup save -t -n src src
269 WVPASS hardlink-test-run-restore
270 WVPASS "$TOP/t/compare-trees" -c src/ src-restore/src/
272 # Test the case where the hardlink hasn't changed, but the tree
273 # needs to be saved again. i.e. the save-cmd.py "if hashvalid:"
276 WVPASS cd "$TOP/bupmeta.tmp"/src
277 WVPASS echo whatever > something-new
280 WVPASS bup save -t -n src src
281 WVPASS hardlink-test-run-restore
282 WVPASS "$TOP/t/compare-trees" -c src/ src-restore/src/
284 # Test hardlink changes between index runs.
286 WVPASS setup-hardlink-test
287 WVPASS cd "$TOP/bupmeta.tmp"/src
288 WVPASS touch hardlink-target-a
289 WVPASS touch hardlink-target-b
290 WVPASS ln hardlink-target-a hardlink-b-1
291 WVPASS ln hardlink-target-a hardlink-a-1
293 WVPASS bup index -vv src
294 WVPASS rm src/hardlink-b-1
295 WVPASS ln src/hardlink-target-b src/hardlink-b-1
296 WVPASS bup index -vv src
297 WVPASS bup save -t -n src src
298 WVPASS hardlink-test-run-restore
299 WVPASS echo ./src/hardlink-a-1 > hardlink-sets.expected
300 WVPASS echo ./src/hardlink-target-a >> hardlink-sets.expected
301 WVPASS echo >> hardlink-sets.expected
302 WVPASS echo ./src/hardlink-b-1 >> hardlink-sets.expected
303 WVPASS echo ./src/hardlink-target-b >> hardlink-sets.expected
304 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
306 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
308 # Test hardlink changes between index and save -- hardlink set [a
309 # b c d] changes to [a b] [c d]. At least right now bup should
310 # notice and recreate the latter.
311 WVPASS setup-hardlink-test
312 WVPASS cd "$TOP/bupmeta.tmp"/src
318 WVPASS bup index -vv src
319 WVPASS rm src/c src/d
321 WVPASS ln src/c src/d
322 WVPASS bup save -t -n src src
323 WVPASS hardlink-test-run-restore
324 WVPASS echo ./src/a > hardlink-sets.expected
325 WVPASS echo ./src/b >> hardlink-sets.expected
326 WVPASS echo >> hardlink-sets.expected
327 WVPASS echo ./src/c >> hardlink-sets.expected
328 WVPASS echo ./src/d >> hardlink-sets.expected
329 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
331 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
333 # Test that we don't link outside restore tree.
334 WVPASS setup-hardlink-test
335 WVPASS cd "$TOP/bupmeta.tmp"
336 WVPASS mkdir src/a src/b
338 WVPASS ln src/a/1 src/b/1
339 WVPASS bup index -vv src
340 WVPASS bup save -t -n src src
341 WVPASS force-delete src-restore
342 WVPASS mkdir src-restore
343 WVPASS bup restore -C src-restore "/src/latest$(pwd)/src/a/"
344 WVPASS test -e src-restore/1
345 WVPASS echo -n > hardlink-sets.expected
346 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
348 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
350 # Test that we do link within separate sub-trees.
351 WVPASS setup-hardlink-test
352 WVPASS cd "$TOP/bupmeta.tmp"
353 WVPASS mkdir src/a src/b
355 WVPASS ln src/a/1 src/b/1
356 WVPASS bup index -vv src/a src/b
357 WVPASS bup save -t -n src src/a src/b
358 WVPASS hardlink-test-run-restore
359 WVPASS echo ./src/a/1 > hardlink-sets.expected
360 WVPASS echo ./src/b/1 >> hardlink-sets.expected
361 (WVPASS cd src-restore; WVPASS hardlink-sets .) > hardlink-sets.restored \
363 WVPASS diff -u hardlink-sets.expected hardlink-sets.restored
366 WVSTART 'meta --edit'
368 WVPASS force-delete "$TOP/bupmeta.tmp"
369 WVPASS mkdir "$TOP/bupmeta.tmp"
370 WVPASS cd "$TOP/bupmeta.tmp"
372 WVPASS bup meta -cf src.meta src
374 WVPASS bup meta --edit --set-uid 0 src.meta | WVPASS bup meta -tvvf - \
375 | WVPASS grep -qE '^uid: 0'
376 WVPASS bup meta --edit --set-uid 1000 src.meta | WVPASS bup meta -tvvf - \
377 | WVPASS grep -qE '^uid: 1000'
379 WVPASS bup meta --edit --set-gid 0 src.meta | WVPASS bup meta -tvvf - \
380 | WVPASS grep -qE '^gid: 0'
381 WVPASS bup meta --edit --set-gid 1000 src.meta | WVPASS bup meta -tvvf - \
382 | WVPASS grep -qE '^gid: 1000'
384 WVPASS bup meta --edit --set-user foo src.meta | WVPASS bup meta -tvvf - \
385 | WVPASS grep -qE '^user: foo'
386 WVPASS bup meta --edit --set-user bar src.meta | WVPASS bup meta -tvvf - \
387 | WVPASS grep -qE '^user: bar'
388 WVPASS bup meta --edit --unset-user src.meta | WVPASS bup meta -tvvf - \
389 | WVPASS grep -qE '^user:'
390 WVPASS bup meta --edit --set-user bar --unset-user src.meta \
391 | WVPASS bup meta -tvvf - | WVPASS grep -qE '^user:'
392 WVPASS bup meta --edit --unset-user --set-user bar src.meta \
393 | WVPASS bup meta -tvvf - | WVPASS grep -qE '^user: bar'
395 WVPASS bup meta --edit --set-group foo src.meta | WVPASS bup meta -tvvf - \
396 | WVPASS grep -qE '^group: foo'
397 WVPASS bup meta --edit --set-group bar src.meta | WVPASS bup meta -tvvf - \
398 | WVPASS grep -qE '^group: bar'
399 WVPASS bup meta --edit --unset-group src.meta | WVPASS bup meta -tvvf - \
400 | WVPASS grep -qE '^group:'
401 WVPASS bup meta --edit --set-group bar --unset-group src.meta \
402 | WVPASS bup meta -tvvf - | WVPASS grep -qE '^group:'
403 WVPASS bup meta --edit --unset-group --set-group bar src.meta \
404 | WVPASS bup meta -tvvf - | grep -qE '^group: bar'
407 WVSTART 'meta --no-recurse'
410 WVPASS force-delete "$TOP/bupmeta.tmp"
411 WVPASS mkdir "$TOP/bupmeta.tmp"
412 WVPASS cd "$TOP/bupmeta.tmp"
415 WVPASS touch src/foo/{1,2,3}
416 WVPASS bup meta -cf src.meta src
417 WVPASSEQ "$(LC_ALL=C; bup meta -tf src.meta | sort)" "src/
422 WVPASS bup meta --no-recurse -cf src.meta src
423 WVPASSEQ "$(LC_ALL=C; bup meta -tf src.meta | sort)" "src/"
426 # Test ownership restoration (when not root or fakeroot).
428 if [ $(t/root-status) != none ]; then
432 first_group="$(WVPASS python -c 'import os,grp; \
433 print grp.getgrgid(os.getgroups()[0])[0]')" || exit $?
434 last_group="$(python -c 'import os,grp; \
435 print grp.getgrgid(os.getgroups()[-1])[0]')" || exit $?
436 last_group_erx="$(escape-erx "$last_group")"
438 WVSTART 'metadata (restoration of ownership)'
439 WVPASS force-delete "$TOP/bupmeta.tmp"
440 WVPASS mkdir "$TOP/bupmeta.tmp"
441 WVPASS cd "$TOP/bupmeta.tmp"
443 # Some systems always assign the parent dir group to new paths
444 # (sgid). Make sure the group is one we're in.
445 WVPASS chgrp -R "$first_group" src
447 WVPASS bup meta -cf src.meta src
451 # Make sure we don't change (or try to change) the user when not root.
452 WVPASS bup meta --edit --set-user root ../src.meta | WVPASS bup meta -x
453 WVPASS bup xstat src | WVPASS grep -qvE '^user: root'
455 WVPASS bup meta --edit --unset-user --set-uid 0 ../src.meta \
457 WVPASS bup xstat src | WVPASS grep -qvE '^user: root'
459 # Make sure we can restore one of the user's groups.
461 WVPASS bup meta --edit --set-group "$last_group" ../src.meta \
463 WVPASS bup xstat src | WVPASS grep -qE "^group: $last_group_erx"
465 # Make sure we can restore one of the user's gids.
467 last_gid="$(echo ${user_gids/* /})"
469 WVPASS bup meta --edit --unset-group --set-gid "$last_gid" ../src.meta \
471 WVPASS bup xstat src | WVPASS grep -qE "^gid: $last_gid"
473 # Test --numeric-ids (gid).
475 current_gidx=$(bup meta -tvvf ../src.meta | grep -e '^gid:')
476 WVPASS bup meta --edit --set-group "$last_group" ../src.meta \
477 | WVPASS bup meta -x --numeric-ids
478 new_gidx=$(bup xstat src | grep -e '^gid:')
479 WVPASSEQ "$current_gidx" "$new_gidx"
481 # Test that restoring an unknown user works.
482 unknown_user=$("$TOP"/t/unknown-owner --user)
484 current_uidx=$(bup meta -tvvf ../src.meta | grep -e '^uid:')
485 WVPASS bup meta --edit --set-user "$unknown_user" ../src.meta \
487 new_uidx=$(bup xstat src | grep -e '^uid:')
488 WVPASSEQ "$current_uidx" "$new_uidx"
490 # Test that restoring an unknown group works.
491 unknown_group=$("$TOP"/t/unknown-owner --group)
493 current_gidx=$(bup meta -tvvf ../src.meta | grep -e '^gid:')
494 WVPASS bup meta --edit --set-group "$unknown_group" ../src.meta \
496 new_gidx=$(bup xstat src | grep -e '^gid:')
497 WVPASSEQ "$current_gidx" "$new_gidx"
500 # Test ownership restoration (when root or fakeroot).
502 if [ $(t/root-status) = none ]; then
506 uid=$(WVPASS id -un) || exit $?
507 gid=$(WVPASS id -gn) || exit $?
509 WVSTART 'metadata (restoration of ownership as root)'
510 WVPASS force-delete "$TOP/bupmeta.tmp"
511 WVPASS mkdir "$TOP/bupmeta.tmp"
512 WVPASS cd "$TOP/bupmeta.tmp"
514 WVPASS chown "$uid:$gid" src # In case the parent dir is sgid, etc.
515 WVPASS bup meta -cf src.meta src
518 WVPASS chmod 700 dest # so we can't accidentally do something insecure
521 other_uinfo="$(id-other-than --user "$uid")"
522 other_user="${other_uinfo%%:*}"
523 other_uid="${other_uinfo##*:}"
525 other_ginfo="$(id-other-than --group "$gid")"
526 other_group="${other_ginfo%%:*}"
527 other_gid="${other_ginfo##*:}"
529 # Make sure we can restore a uid (must be in /etc/passwd b/c cygwin).
530 WVPASS bup meta --edit --unset-user --set-uid "$other_uid" ../src.meta \
532 WVPASS bup xstat src | WVPASS grep -qE "^uid: $other_uid"
534 # Make sure we can restore a gid (must be in /etc/group b/c cygwin).
535 WVPASS bup meta --edit --unset-group --set-gid "$other_gid" ../src.meta \
537 WVPASS bup xstat src | WVPASS grep -qE "^gid: $other_gid"
539 other_uinfo2="$(id-other-than --user "$(id -un)" "$other_user")"
540 other_user2="${other_uinfo2%%:*}"
541 other_user2_erx="$(escape-erx "$other_user2")"
542 other_uid2="${other_uinfo2##*:}"
544 other_ginfo2="$(id-other-than --group "$(id -gn)" "$other_group")"
545 other_group2="${other_ginfo2%%:*}"
546 other_group2_erx="$(escape-erx "$other_group2")"
547 other_gid2="${other_ginfo2##*:}"
549 # Try to restore a user (and see that user trumps uid when uid is not 0).
550 WVPASS bup meta --edit \
551 --set-uid "$other_uid" --set-user "$other_user2" ../src.meta \
553 WVPASS bup xstat src | WVPASS grep -qE "^user: $other_user2_erx"
555 # Try to restore a group (and see that group trumps gid when gid is not 0).
556 WVPASS bup meta --edit \
557 --set-gid "$other_gid" --set-group "$other_group2" ../src.meta \
559 WVPASS bup xstat src | WVPASS grep -qE "^group: $other_group2_erx"
561 # Test --numeric-ids (uid). Note the name 'root' is not handled
562 # specially, so we use that here as the test user name. We assume
563 # that the root user's uid is never 42.
565 WVPASS bup meta --edit --set-user root --set-uid "$other_uid" ../src.meta \
566 | WVPASS bup meta -x --numeric-ids
567 new_uidx=$(bup xstat src | grep -e '^uid:')
568 WVPASSEQ "$new_uidx" "uid: $other_uid"
570 # Test --numeric-ids (gid). Note the name 'root' is not handled
571 # specially, so we use that here as the test group name. We
572 # assume that the root group's gid is never 42.
574 WVPASS bup meta --edit --set-group root --set-gid "$other_gid" ../src.meta \
575 | WVPASS bup meta -x --numeric-ids
576 new_gidx=$(bup xstat src | grep -e '^gid:')
577 WVPASSEQ "$new_gidx" "gid: $other_gid"
579 # Test that restoring an unknown user works.
580 unknown_user=$("$TOP"/t/unknown-owner --user)
582 WVPASS bup meta --edit \
583 --set-uid "$other_uid" --set-user "$unknown_user" ../src.meta \
585 new_uidx=$(bup xstat src | grep -e '^uid:')
586 WVPASSEQ "$new_uidx" "uid: $other_uid"
588 # Test that restoring an unknown group works.
589 unknown_group=$("$TOP"/t/unknown-owner --group)
591 WVPASS bup meta --edit \
592 --set-gid "$other_gid" --set-group "$unknown_group" ../src.meta \
594 new_gidx=$(bup xstat src | grep -e '^gid:')
595 WVPASSEQ "$new_gidx" "gid: $other_gid"
597 if ! [[ $(uname) =~ CYGWIN ]]; then
598 # For now, skip these on Cygwin because it doesn't allow
599 # restoring an unknown uid/gid.
601 # Make sure a uid of 0 trumps a non-root user.
602 WVPASS bup meta --edit --set-user "$other_user2" ../src.meta \
604 WVPASS bup xstat src | WVPASS grep -qvE "^user: $other_user2_erx"
605 WVPASS bup xstat src | WVPASS grep -qE "^uid: 0"
607 # Make sure a gid of 0 trumps a non-root group.
608 WVPASS bup meta --edit --set-group "$other_group2" ../src.meta \
610 WVPASS bup xstat src | WVPASS grep -qvE "^group: $other_group2_erx"
611 WVPASS bup xstat src | WVPASS grep -qE "^gid: 0"
616 # Root-only tests that require an FS with all the trimmings: ACLs,
617 # Linux attr, Linux xattr, etc.
618 if [ $(t/root-status) = root ]; then
620 # Some cleanup handled in universal-cleanup() above.
621 # These tests are only likely to work under Linux for now
623 [[ $(uname) =~ Linux ]] || exit 0
625 WVSTART 'meta - general (as root)'
626 WVPASS setup-test-tree
627 WVPASS cd "$TOP/bupmeta.tmp"
630 WVPASS dd if=/dev/zero of=testfs.img bs=1M count=32
631 # Make sure we have all the options the chattr test needs
632 # (i.e. create a "normal" ext4 filesystem).
633 WVPASS mke2fs -F -m 0 \
635 -O has_journal,extent,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize \
638 WVPASS mount -o loop,acl,user_xattr testfs.img testfs
639 # Hide, so that tests can't create risks.
640 WVPASS chown root:root testfs
641 WVPASS chmod 0700 testfs
643 umount testfs-limited
644 WVPASS dd if=/dev/zero of=testfs-limited.img bs=1M count=32
645 WVPASS mkfs -t vfat testfs-limited.img
646 WVPASS mkdir testfs-limited
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)'