exclude.test 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #! /bin/sh
  2. # Copyright (C) 2003, 2004, 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 exclude/include directives.
  6. # Test some of the more obscure wildcard handling of exclude/include
  7. # processing.
  8. . "$suitedir/rsync.fns"
  9. CVSIGNORE='*.junk'
  10. export CVSIGNORE
  11. # Build some files/dirs/links to copy
  12. makepath "$fromdir/foo/down/to/you"
  13. makepath "$fromdir/foo/sub"
  14. makepath "$fromdir/bar/down/to/foo/too"
  15. makepath "$fromdir/bar/down/to/bar/baz"
  16. makepath "$fromdir/mid/for/foo/and/that/is/who"
  17. makepath "$fromdir/new/keep/this"
  18. makepath "$fromdir/new/lose/this"
  19. cat >"$fromdir/.filt" <<EOF
  20. exclude down
  21. : .filt-temp
  22. clear
  23. - .filt
  24. - *.bak
  25. - *.old
  26. EOF
  27. echo filtered-1 >"$fromdir/foo/file1"
  28. echo removed >"$fromdir/foo/file2"
  29. echo cvsout >"$fromdir/foo/file2.old"
  30. cat >"$fromdir/foo/.filt" <<EOF
  31. include .filt
  32. - /file1
  33. EOF
  34. echo not-filtered-1 >"$fromdir/foo/sub/file1"
  35. cat >"$fromdir/bar/.filt" <<EOF
  36. - home-cvs-exclude
  37. dir-merge .filt2
  38. + to
  39. EOF
  40. echo cvsout >"$fromdir/bar/down/to/home-cvs-exclude"
  41. cat >"$fromdir/bar/down/to/.filt2" <<EOF
  42. - .filt2
  43. EOF
  44. cat >"$fromdir/bar/down/to/foo/.filt2" <<EOF
  45. + *.junk
  46. EOF
  47. echo keeper >"$fromdir/bar/down/to/foo/file1"
  48. echo cvsout >"$fromdir/bar/down/to/foo/file1.bak"
  49. echo gone >"$fromdir/bar/down/to/foo/file3"
  50. echo lost >"$fromdir/bar/down/to/foo/file4"
  51. echo weird >"$fromdir/bar/down/to/foo/+ file3"
  52. echo cvsout-but-filtin >"$fromdir/bar/down/to/foo/file4.junk"
  53. echo smashed >"$fromdir/bar/down/to/foo/to"
  54. cat >"$fromdir/bar/down/to/bar/.filt2" <<EOF
  55. - *.deep
  56. EOF
  57. echo filtout >"$fromdir/bar/down/to/bar/baz/file5.deep"
  58. # This one should be ineffectual
  59. cat >"$fromdir/mid/.filt2" <<EOF
  60. - extra
  61. EOF
  62. echo cvsout >"$fromdir/mid/one-in-one-out"
  63. echo one-in-one-out >"$fromdir/mid/.cvsignore"
  64. echo cvsin >"$fromdir/mid/one-for-all"
  65. cat >"$fromdir/mid/.filt" <<EOF
  66. :C
  67. EOF
  68. echo cvsin >"$fromdir/mid/for/one-in-one-out"
  69. echo expunged >"$fromdir/mid/for/foo/extra"
  70. echo retained >"$fromdir/mid/for/foo/keep"
  71. # Setup our test exclude/include files.
  72. excl="$scratchdir/exclude-from"
  73. cat >"$excl" <<EOF
  74. !
  75. # If the second line of these two lines does anything, it's a bug.
  76. + **/bar
  77. - /bar
  78. # This should match against the whole path, not just the name.
  79. + foo**too
  80. # These should float at the end of the path.
  81. + foo/s?b/
  82. - foo/*/
  83. # Test how /** differs from /***
  84. - new/keep/**
  85. - new/lose/***
  86. # Test some normal excludes. Competing lines are paired.
  87. + t[o]/
  88. - to
  89. + file4
  90. - file[2-9]
  91. - /mid/for/foo/extra
  92. EOF
  93. cat >"$scratchdir/.cvsignore" <<EOF
  94. home-cvs-exclude
  95. EOF
  96. # Start with a check of --prune-empty-dirs:
  97. $RSYNC -av -f -_foo/too/ -f -_foo/down/ -f -_foo/and/ -f -_new/ "$fromdir/" "$chkdir/"
  98. checkit "$RSYNC -av --prune-empty-dirs '$fromdir/' '$todir/'" "$chkdir" "$todir"
  99. rm -rf "$todir"
  100. # Add a directory symlink.
  101. ln -s too "$fromdir/bar/down/to/foo/sym"
  102. # Create chkdir with what we expect to be excluded.
  103. checkit "$RSYNC -avv '$fromdir/' '$chkdir/'" "$fromdir" "$chkdir"
  104. sleep 1 # Ensures that the rm commands will tweak the directory times.
  105. rm -r "$chkdir"/foo/down
  106. rm -r "$chkdir"/mid/for/foo/and
  107. rm -r "$chkdir"/new/keep/this
  108. rm -r "$chkdir"/new/lose
  109. rm "$chkdir"/foo/file[235-9]
  110. rm "$chkdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo/file[235-9]
  111. rm "$chkdir"/mid/for/foo/extra
  112. # Un-tweak the directory times in our first (weak) exclude test (though
  113. # it's a good test of the --existing option).
  114. $RSYNC -av --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
  115. # Now, test if rsync excludes the same files.
  116. checkit "$RSYNC -avv --exclude-from='$excl' \
  117. --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
  118. # Modify the chk dir by removing cvs-ignored files and then tweaking the dir times.
  119. rm "$chkdir"/foo/*.old
  120. rm "$chkdir"/bar/down/to/foo/*.bak
  121. rm "$chkdir"/bar/down/to/foo/*.junk
  122. rm "$chkdir"/bar/down/to/home-cvs-exclude
  123. rm "$chkdir"/mid/one-in-one-out
  124. $RSYNC -av --existing --filter='exclude,! */' "$fromdir/" "$chkdir/"
  125. # Now, test if rsync excludes the same files, this time with --cvs-exclude
  126. # and --delete-excluded.
  127. checkit "$RSYNC -avvC --filter='merge $excl' --delete-excluded \
  128. --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
  129. # Modify the chk dir for our merge-exclude test and then tweak the dir times.
  130. rm "$chkdir"/foo/file1
  131. rm "$chkdir"/bar/down/to/bar/baz/*.deep
  132. cp_touch "$fromdir"/bar/down/to/foo/*.junk "$chkdir"/bar/down/to/foo
  133. cp_touch "$fromdir"/bar/down/to/foo/to "$chkdir"/bar/down/to/foo
  134. $RSYNC -av --existing -f 'show .filt*' -f 'hide,! */' --del "$fromdir/" "$todir/"
  135. echo retained >"$todir"/bar/down/to/bar/baz/nodel.deep
  136. cp_touch "$todir"/bar/down/to/bar/baz/nodel.deep "$chkdir"/bar/down/to/bar/baz
  137. $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
  138. # Now, test if rsync excludes the same files, this time with a merge-exclude
  139. # file.
  140. checkit "sed '/!/d' '$excl' |
  141. $RSYNC -avv -f dir-merge_.filt -f merge_- \
  142. --delete-during '$fromdir/' '$todir/'" "$chkdir" "$todir"
  143. # Remove the files that will be deleted.
  144. rm "$chkdir"/.filt
  145. rm "$chkdir"/bar/.filt
  146. rm "$chkdir"/bar/down/to/.filt2
  147. rm "$chkdir"/bar/down/to/foo/.filt2
  148. rm "$chkdir"/bar/down/to/bar/.filt2
  149. rm "$chkdir"/mid/.filt
  150. $RSYNC -av --protocol=28 --existing --include='*/' --exclude='*' "$fromdir/" "$chkdir/"
  151. # Now, try the prior command with --delete-before and some side-specific
  152. # rules.
  153. checkit "sed '/!/d' '$excl' |
  154. $RSYNC -avv -f :s_.filt -f .s_- -f P_nodel.deep \
  155. --delete-before '$fromdir/' '$todir/'" "$chkdir" "$todir"
  156. # Next, we'll test some rule-restricted filter files.
  157. cat >"$fromdir/bar/down/.excl" <<EOF
  158. file3
  159. EOF
  160. cat >"$fromdir/bar/down/to/foo/.excl" <<EOF
  161. + file3
  162. *.bak
  163. EOF
  164. $RSYNC -av --del "$fromdir/" "$chkdir/"
  165. rm "$chkdir/bar/down/to/foo/file1.bak"
  166. rm "$chkdir/bar/down/to/foo/file3"
  167. rm "$chkdir/bar/down/to/foo/+ file3"
  168. $RSYNC -av --existing --filter='-! */' "$fromdir/" "$chkdir/"
  169. $RSYNC -av --delete-excluded --exclude='*' "$fromdir/" "$todir/"
  170. checkit "$RSYNC -avv -f dir-merge,-_.excl \
  171. '$fromdir/' '$todir/'" "$chkdir" "$todir"
  172. relative_opts='--relative --chmod=Du+w --copy-unsafe-links'
  173. $RSYNC -av $relative_opts "$fromdir/foo" "$chkdir/"
  174. rm -rf "$chkdir$fromdir/foo/down"
  175. $RSYNC -av $relative_opts --existing --filter='-! */' "$fromdir/foo" "$chkdir/"
  176. checkit "$RSYNC -avv $relative_opts --exclude='$fromdir/foo/down' \
  177. '$fromdir/foo' '$todir'" "$chkdir$fromdir/foo" "$todir$fromdir/foo"
  178. # The script would have aborted on error, so getting here means we've won.
  179. exit 0