delete.test 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #! /bin/sh
  2. # Copyright (C) 2005 by Wayne Davison <wayned@samba.org>
  3. # This program is distributable under the terms of the GNU GPL (see
  4. # COPYING).
  5. # Test rsync handling of various delete directives.
  6. . "$suitedir/rsync.fns"
  7. hands_setup
  8. makepath "$chkdir" "$todir/extradir" "$todir/emptydir/subdir"
  9. echo extra >"$todir"/remove1
  10. echo extra >"$todir"/remove2
  11. echo extra >"$todir"/extradir/remove3
  12. echo extra >"$todir"/emptydir/subdir/remove4
  13. # Create two chk dirs, one with a copy of the source files, and one with
  14. # what we expect to be left behind by the copy using --remove-source-files.
  15. # Also, make sure that --dry-run --del doesn't output anything extraneous.
  16. $RSYNC -av "$fromdir/" "$chkdir/copy/" >"$tmpdir/copy.out" 2>&1
  17. cat "$tmpdir/copy.out"
  18. egrep -v '^(created directory|sent|total size) ' "$tmpdir/copy.out" >"$tmpdir/copy.new"
  19. mv "$tmpdir/copy.new" "$tmpdir/copy.out"
  20. $RSYNC -avn --del "$fromdir/" "$chkdir/copy2/" >"$tmpdir/copy2.out" 2>&1 || true
  21. cat "$tmpdir/copy2.out"
  22. egrep -v '^(created directory|sent|total size) ' "$tmpdir/copy2.out" >"$tmpdir/copy2.new"
  23. mv "$tmpdir/copy2.new" "$tmpdir/copy2.out"
  24. diff $diffopt "$tmpdir/copy.out" "$tmpdir/copy2.out"
  25. $RSYNC -av -f 'exclude,! */' "$fromdir/" "$chkdir/empty/"
  26. checkit "$RSYNC -avv --del --remove-source-files '$fromdir/' '$todir/'" "$chkdir/copy" "$todir"
  27. diff -r "$chkdir/empty" "$fromdir"
  28. # Make sure that "P" but not "-" per-dir merge-file filters take effect with
  29. # --delete-excluded.
  30. cat >"$todir/filters" <<EOF
  31. P foo
  32. - bar
  33. EOF
  34. touch "$todir/foo" "$todir/bar" "$todir/baz"
  35. $RSYNC -r --exclude=baz --filter=': filters' --delete-excluded "$fromdir/" "$todir/"
  36. test -f "$todir/foo" || test_fail "rsync should NOT have deleted $todir/foo"
  37. test -f "$todir/bar" && test_fail "rsync SHOULD have deleted $todir/bar"
  38. test -f "$todir/baz" && test_fail "rsync SHOULD have deleted $todir/baz"
  39. # The script would have aborted on error, so getting here means we've won.
  40. exit 0