File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / rsync / testsuite / exclude.test
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 00:32:36 2021 UTC (3 years, 3 months ago) by misho
Branches: rsync, MAIN
CVS tags: v3_2_3, HEAD
rsync 3.2.3

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>