Show symlink targets
[rsync/rsync.git] / testsuite / rsync.fns
CommitLineData
d820215b
MP
1#! /bin/sh
2
3# Copyright (C) 2001 by Martin Pool <mbp@samba.org>
4
5# General-purpose test functions for rsync.
3a4c683f 6
0154b302
MP
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version
9# 2 as published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Lesser General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public
17# License along with this program; if not, write to the Free Software
18# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20
3a4c683f
MP
21TMP="$scratchdir"
22FROM=${TMP}/from
23TO=${TMP}/to
3a4c683f 24LOG=${TMP}/log
3fedd74b 25RSYNC="$rsync_bin"
3a4c683f
MP
26
27runtest() {
28 echo $ECHO_N "Test $1: $ECHO_C"
501972bf
MP
29 if eval "$2"
30 then
31 echo "${ECHO_T} done."
32 return 0
33 else
34 echo "${ECHO_T} failed!"
35 return 1
36 fi
3a4c683f
MP
37}
38
39printmsg() {
40 echo "$1"
41}
42
e052b21f 43
6773a779 44rsync_ls_lR() {
57835c00
MP
45 find "$@" -print | sort | xargs $TLS
46}
47
48
e052b21f
MP
49####################
50# Build test directories TO and FROM, with FROM full of files.
51
3a4c683f 52hands_setup() {
501972bf
MP
53 # Clean before creation
54 rm -rf $FROM
55 rm -rf $TO
56
3a4c683f
MP
57 [ -d $FROM ] || mkdir $FROM
58 [ -d $TO ] || mkdir $TO
59
e052b21f
MP
60 # On some BSD systems, the umask affects the mode of created
61 # symlinks, even though the mode apparently has no effect on how
62 # the links behave in the future, and it cannot be changed using
63 # chmod! rsync always sets its umask to 000 so that it can
64 # accurately recreate permissions, but this script is probably run
65 # with a different umask.
66
67 # This causes a little problem that "ls -l" of the two will not be
68 # the same. So, we need to set our umask before doing any creations.
69
3a4c683f
MP
70 # set up test data
71 touch ${FROM}/empty
72 mkdir ${FROM}/emptydir
e8ca5901 73
571a4b26 74 # a hundred lines of text or so
57835c00 75 rsync_ls_lR ${srcdir} > ${FROM}/filelist
3a4c683f
MP
76
77 # This might fail on systems that don't have -n
78 echo $ECHO_N "This file has no trailing lf$ECHO_C" > ${FROM}/nolf
0154b302 79 umask 0
3a4c683f 80 ln -s nolf ${FROM}/nolf-symlink
4c80c473 81 umask 022
0154b302 82
4c80c473 83 cat $srcdir/*.c > ${FROM}/text
3a4c683f 84 mkdir ${FROM}/dir
4c80c473 85 cp ${FROM}/text ${FROM}/dir
3a4c683f
MP
86 mkdir ${FROM}/dir/subdir
87 mkdir ${FROM}/dir/subdir/subsubdir
88 ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
89 mkdir ${FROM}/dir/subdir/subsubdir2
90 ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
7d691654 91
8f98c608
MP
92# echo testing head:
93# ls -lR ${srcdir} | head -10 || echo failed
3a4c683f 94}
3fedd74b
MP
95
96
e052b21f 97
99cdaff7
MP
98
99####################
100# Many machines do not have "mkdir -p", so we have to build up long paths.
101# How boring.
102makepath () {
7c1b7890 103 echo " makepath $1"
99cdaff7
MP
104 p="$1"
105 (
106 # Absolut Unix.
107 if echo $p | grep '^/' >/dev/null
108 then
109 cd /
110 fi
111
112 # This will break if $1 contains a space.
113 for c in `echo $p | tr '/' ' '`
114 do
7c1b7890 115 [ -d "$c" ] || mkdir "$c" || { echo "failed to create $c" >&2; return $? }
99cdaff7
MP
116 cd "$c" || return $?
117 done
118 )
119}
120
121
122
3fedd74b
MP
123###########################
124# Run a test (in '$1') then compare directories $2 and $3 to see if
125# there are any difference. If there are, explain them.
126
127checkit() {
128 log=${LOG}
129 failed=
130 # the log accumulates all output; we only display it if there
131 # is a problem.
132
133 echo "Running: \"$1\"" >${log}
134 echo "">>${log}
135 eval "$1" >>${log} 2>&1
136 status=$?
137 if [ $status != 0 ]; then
138 failed="YES";
139 fi
140
141 echo "-------------">>${log}
142 echo "check how the files compare with diff:">>${log}
143 echo "">>${log}
37c3cf43 144 diff -cr $2 $3 >>${log} 2>&1 || failed=YES
3fedd74b
MP
145 echo "-------------">>${log}
146 echo "check how the directory listings compare with diff:">>${log}
147 echo "">>${log}
054b40b6
MP
148 ( cd "$2" && rsync_ls_lR ) > ${TMP}/ls-from 2>>${log}
149 ( cd "$3" && rsync_ls_lR ) > ${TMP}/ls-to 2>>${log}
37c3cf43 150 diff -c ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES
3fedd74b 151 if [ -z "${failed}" ] ; then
3fedd74b
MP
152 rm $log
153 return 0
154 else
3fedd74b
MP
155 cat ${log}
156 rm ${log}
157 return 1
158 fi
159}
160
863dff51
MP
161
162# In fact, we need a more general feature of capturing all stderr/log files,
163# and dumping them if something goes wrong.
164
165checkforlogs() {
166 # skip it if we're under debian-test
167 if test -n "${Debian}" ; then return 0 ; fi
168
169 if [ -f $1 -a -s $1 ] ; then
170 echo "Failures have occurred. $1 follows:" >&2
171 cat $1 >&2
172 exit 1
173 fi
174}
175
d2094cc3 176
4a7cb3e8 177build_rsyncd_conf() {
d2094cc3
MP
178 # Build an appropriate configuration file
179 conf="$scratchdir/test-rsyncd.conf"
180 echo "building configuration $conf"
181
182 port=2612
183 pidfile="$scratchdir/rsyncd.pid"
184 logfile="$scratchdir/rsyncd.log"
185
186 cat >$conf <<EOF
3aae15ec 187# rsyncd configuration file autogenerated by $0
d2094cc3 188
3aae15ec
MP
189pid file = $pidfile
190use chroot = no
191hosts allow = localhost, 127.0.0.1
192log file = $logfile
d2094cc3 193
3aae15ec
MP
194[test-from] = $scratchdir/daemon-from/
195 read only = yes
d2094cc3 196
3aae15ec
MP
197[test-to] = $scratchdir/daemon-to/
198 read only = no
d2094cc3
MP
199EOF
200}
201
202