Implement --tweak, --no-tweak, --no-tweak-hlinked options.
[rsync/rsync.git] / testsuite / tweak-opts.test
CommitLineData
7359a58b
MM
1#! /bin/sh
2
3# This program is distributable under the terms of the GNU GPL (see
4# COPYING).
5
6# Test the --tweak, --no-tweak, and --no-tweak-hlinked options.
7
8. $srcdir/testsuite/rsync.fns
9
10# Replacement for [ a -ef b ] that doesn't follow symlinks.
11samefile() {
12 inum1=`ls -di "$1" | sed 's/ .*$//'`
13 inum2=`ls -di "$2" | sed 's/ .*$//'`
14 [ "$inum1" = "$inum2" ]
15}
16
17chkfile="$scratchdir/rsync.chk"
18outfile="$scratchdir/rsync.out"
19
20makepath "$fromdir"
21
22# usage: testit OPTION FTYPE ATTR
23testit() {
24 option="$1"
25 ftype=$2
26 attr=$3
27 testid="$option $ftype $attr"
28 echo "Running test: ($testid)"
29
30 # Prepare the destination directory:
31 # file1: attr different from source
32 # file2: attr different from source, hard-linked with file2hl
33 # file3: attr same as source, hard-linked with file3hl
34 extraopt=''
35 rm -rf "$todir"
36 $RSYNC -a "$fromdir/" "$todir/"
37 case "$ftype,$attr" in
38 *,p)
39 chmod 700 "$todir/file1" "$todir/file2"
40 icode='...p.....'
41 ;;
42 L,t)
43 # Grab the new symlinks.
44 $RSYNC -a "$scratchdir/newlinks/" "$todir/"
45 icode='..t......'
46 ;;
47 *,t)
48 touch -d @1194208678 "$todir/file1" "$todir/file2"
49 # Make sure unchanged_attrs signals a difference in mtime.
50 extraopt='--checksum'
51 icode='..t......'
52 ;;
53 t_symlink)
54 esac
55 ln "$todir/file2" "$todir/file2hl"
56 ln "$todir/file3" "$todir/file3hl"
57
58 # Determine the expected results.
59 case "$option" in
60 ''|*--tweak)
61 # Tweak both files, tweaking through to file2hl.
62 a1='.'
63 a2='.'
64 changes_f2hl=1
65 ;;
66 --no-tweak-hlinked)
67 # Tweak file1 and recreate file2, breaking the link to file2hl.
68 a1='.'
69 a2='c'
70 changes_f2hl=''
71 ;;
72 --no-tweak)
73 # Recreate both file1 and file2, breaking the link to file2hl.
74 a1='c'
75 a2='c'
76 changes_f2hl=''
77 ;;
78 esac
79 if [ "$ftype" = L ]; then
80 ltgt=' -> foo'
81 else
82 ltgt=''
83 fi
84 cat >"$chkfile" <<EOCHK
85$a1$ftype$icode file1$ltgt
86$a2$ftype$icode file2$ltgt
87EOCHK
88
89 $RSYNC -a -i --omit-dir-times $option $extraopt "$fromdir/" "$todir/" | tee "$outfile"
90 diff $diffopt "$chkfile" "$outfile" || test_fail "itemize mismatch for test ($testid)"
91
92 if [ $changes_f2hl ]; then
93 samefile "$todir/file2" "$todir/file2hl" || test_fail "rsync should not have broken the file2 hard link"
94 if [ $attr = p ]; then
95 check_perms "$todir/file2hl" rw------- "test ($testid)"
96 fi
97 else
98 ! samefile "$todir/file2" "$todir/file2hl" || test_fail "rsync should have broken the file2 hard link"
99 if [ $attr = p ]; then
100 check_perms "$todir/file2hl" rwx------ "test ($testid)"
101 fi
102 fi
103
104 # Nothing should ever happen to file3.
105 samefile "$todir/file3" "$todir/file3hl" || test_fail "rsync should not have broken the file3 hard link"
106}
107
108# REGULAR FILES
109echo data >"$fromdir/file1"
110echo data >"$fromdir/file2"
111echo data >"$fromdir/file3"
112chmod 600 "$fromdir/file1" "$fromdir/file2" "$fromdir/file3"
113for o in '' '--no-tweak --tweak' '--no-tweak-hlinked' '--no-tweak'; do
114 for a in p t; do
115 testit "$o" f $a
116 done
117done
118
119# SYMLINKS
120rm -f "$fromdir/file1" "$fromdir/file2" "$fromdir/file3"
121if config_test CAN_HARDLINK_SYMLINK && config_test HAVE_LUTIMES; then
122 ln -s foo "$fromdir/file1"
123 ln -s foo "$fromdir/file2"
124 ln -s foo "$fromdir/file3"
125 # Since we don't have `touch -h', sleep once and make some newer
126 # symlinks that each test can copy into the destination directory.
127 sleep 1
128 makepath "$scratchdir/newlinks"
129 ln -s foo "$scratchdir/newlinks/file1"
130 ln -s foo "$scratchdir/newlinks/file2"
131 for o in '' '--no-tweak --tweak' '--no-tweak-hlinked' '--no-tweak'; do
132 # For symlinks, we test only times, not permissions.
133 testit "$o" L t
134 done
135fi
136
137# SPECIAL FILES
138rm -f "$fromdir/file1" "$fromdir/file2" "$fromdir/file3"
139if config_test CAN_HARDLINK_SPECIAL \
140 && mkfifo "$fromdir/file1" "$fromdir/file2" "$fromdir/file3"; then
141 chmod 600 "$fromdir/file1" "$fromdir/file2" "$fromdir/file3"
142 for o in '' '--no-tweak --tweak' '--no-tweak-hlinked' '--no-tweak'; do
143 for a in p t; do
144 testit "$o" S $a
145 done
146 done
147fi
148
149# The script would have aborted on error, so getting here means we've won.
150exit 0