Fiddle umask again.
[rsync/rsync.git] / testsuite / rsync.fns
1 #! /bin/sh
2
3 # Copyright (C) 2001 by Martin Pool <mbp@samba.org>
4
5 # General-purpose test functions for rsync.
6
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
21 TMP="$scratchdir"
22 FROM=${TMP}/from
23 TO=${TMP}/to
24 F1=text1
25 LOG=${TMP}/log
26 RSYNC="$rsync_bin"
27
28 runtest() {
29     echo $ECHO_N "Test $1: $ECHO_C"
30     eval "$2"
31 }
32
33 printmsg() {
34     echo "$1"
35 }
36
37
38 ####################
39 # Build test directories TO and FROM, with FROM full of files.
40
41 hands_setup() {
42     [ -d $FROM ] || mkdir $FROM
43     [ -d $TO ] || mkdir $TO
44
45     # On some BSD systems, the umask affects the mode of created
46     # symlinks, even though the mode apparently has no effect on how
47     # the links behave in the future, and it cannot be changed using
48     # chmod!  rsync always sets its umask to 000 so that it can
49     # accurately recreate permissions, but this script is probably run
50     # with a different umask. 
51
52     # This causes a little problem that "ls -l" of the two will not be
53     # the same.  So, we need to set our umask before doing any creations.
54
55     # set up test data
56     touch ${FROM}/empty
57     mkdir ${FROM}/emptydir
58
59     # a few hundred lines of test
60     ls -lR / | head -200 > ${FROM}/filelist
61
62     # This might fail on systems that don't have -n
63     echo $ECHO_N "This file has no trailing lf$ECHO_C" > ${FROM}/nolf
64     umask 0
65     ln -s nolf ${FROM}/nolf-symlink
66     umask 077
67
68     cat $srcdir/*.c | head -2000 > ${FROM}/${F1}
69     mkdir ${FROM}/dir
70     cp ${FROM}/${F1} ${FROM}/dir
71     mkdir ${FROM}/dir/subdir
72     mkdir ${FROM}/dir/subdir/subsubdir
73     ls -ltr /etc > ${FROM}/dir/subdir/subsubdir/etc-ltr-list
74     mkdir ${FROM}/dir/subdir/subsubdir2
75     ls -lt /bin > ${FROM}/dir/subdir/subsubdir2/bin-lt-list
76 }
77
78
79
80 ###########################
81 # Run a test (in '$1') then compare directories $2 and $3 to see if
82 # there are any difference.  If there are, explain them.
83
84 checkit() {
85     log=${LOG}
86     failed=
87     # the log accumulates all output; we only display it if there 
88     # is a problem.
89
90     echo "Running: \"$1\""  >${log}
91     echo "">>${log}
92     eval "$1"  >>${log} 2>&1
93     status=$?
94     if [ $status != 0 ]; then
95         failed="YES";
96     fi
97
98     echo "-------------">>${log}
99     echo "check how the files compare with diff:">>${log}
100     echo "">>${log}
101     diff -cr $2 $3 >>${log} 2>&1 || failed=YES
102     echo "-------------">>${log}
103     echo "check how the directory listings compare with diff:">>${log}
104     echo "">>${log}
105     ( cd $2 ; ls -laR ) > ${TMP}/ls-from 2>>${log}
106     ( cd $3 ; ls -laR ) > ${TMP}/ls-to  2>>${log}
107     diff -c ${TMP}/ls-from ${TMP}/ls-to >>${log} 2>&1 || failed=YES
108     if [ -z "${failed}" ] ; then
109         echo "${ECHO_T} done."
110         rm $log
111         return 0
112     else
113         echo "${ECHO_T} failed!"
114         cat ${log}
115         rm ${log}
116         return 1
117     fi
118 }
119
120
121 # In fact, we need a more general feature of capturing all stderr/log files,
122 # and dumping them if something goes wrong.
123
124 checkforlogs() {
125   # skip it if we're under debian-test
126   if test -n "${Debian}" ; then return 0 ; fi
127
128   if [ -f $1 -a -s $1 ] ; then
129         echo "Failures have occurred.  $1 follows:" >&2
130         cat $1 >&2
131         exit 1
132   fi
133 }
134
135
136 build_rsyncd_conf() {
137     # Build an appropriate configuration file
138     conf="$scratchdir/test-rsyncd.conf"
139     echo "building configuration $conf"
140
141     port=2612
142     pidfile="$scratchdir/rsyncd.pid"
143     logfile="$scratchdir/rsyncd.log"
144
145     cat >$conf <<EOF
146 # rsyncd configuration file autogenerated by $0
147
148 pid file = $pidfile
149 use chroot = no
150 hosts allow = localhost, 127.0.0.1
151 log file = $logfile
152
153 [test-from] = $scratchdir/daemon-from/
154         read only = yes
155
156 [test-to] = $scratchdir/daemon-to/
157         read only = no
158 EOF
159 }
160
161