More tweaks for Actions.
[rsync.git] / testsuite / xattrs.test
1 #! /bin/sh
2
3 # This program is distributable under the terms of the GNU GPL (see
4 # COPYING).
5
6 # Test that rsync handles basic xattr preservation.
7
8 . $suitedir/rsync.fns
9 lnkdir="$tmpdir/lnk"
10
11 $RSYNC --version | grep ", xattrs" >/dev/null || test_skipped "Rsync is configured without xattr support"
12
13 case "$HOST_OS" in
14 darwin*)
15     xset() {
16         xnam="$1"
17         xval="$2"
18         shift 2
19         xattr -s "$xnam" "$xval" "${@}"
20     }
21     xls() {
22         xattr -l "${@}" | sed "s/^[ $tab_ch]*//"
23     }
24     RSYNC_PREFIX='rsync'
25     RUSR='rsync.nonuser'
26     ;;
27 solaris*)
28     xset() {
29         xnam="$1"
30         xval="$2"
31         shift 2
32         for fn in "${@}"; do
33             runat "$fn" "$SHELL_PATH" <<EOF
34 echo "${xval}" > "${xnam}"
35 EOF
36         done
37     }
38     xls() {
39         for fn in "${@}"; do
40             runat "$fn" "$SHELL_PATH" <<EOF
41 for x in *; do echo "\$x=\`cat \$x\`"; done
42 EOF
43        done
44     }
45     RSYNC_PREFIX='rsync'
46     RUSR='rsync.nonuser'
47     ;;
48 *)
49     xset() {
50         xnam="$1"
51         xval="$2"
52         shift 2
53         setfattr -n "$xnam" -v "$xval" "${@}"
54     }
55     xls() {
56         getfattr -d "${@}"
57     }
58     RSYNC_PREFIX='user.rsync'
59     RUSR='user.rsync'
60     ;;
61 esac
62
63 makepath "$lnkdir" "$fromdir/foo/bar"
64 echo now >"$fromdir/file0"
65 echo something >"$fromdir/file1"
66 echo else >"$fromdir/file2"
67 echo deep >"$fromdir/foo/file3"
68 echo normal >"$fromdir/file4"
69 echo deeper >"$fromdir/foo/bar/file5"
70
71 makepath "$chkdir/foo"
72 echo wow >"$chkdir/file1"
73 cp_touch "$fromdir/foo/file3" "$chkdir/foo"
74
75 dirs='foo foo/bar'
76 files='file0 file1 file2 foo/file3 file4 foo/bar/file5'
77
78 uid_gid=`"$TOOLDIR/tls" "$fromdir/foo" | sed 's/^.* \([0-9][0-9]*\)\.\([0-9][0-9]*\) .*/\1:\2/'`
79
80 cd "$fromdir"
81
82 xset user.foo foo file0 2>/dev/null || test_skipped "Unable to set an xattr"
83 xset user.bar bar file0
84
85 xset user.short 'this is short' file1
86 xset user.long 'this is a long attribute that will be truncated in the initial data send' file1
87 xset user.good 'this is good' file1
88 xset user.nice 'this is nice' file1
89
90 xset user.foo foo file2
91 xset user.bar bar file2
92 xset user.long 'a long attribute for our new file that tests to ensure that this works' file2
93
94 xset user.dir1 'need to test directory xattrs too' foo
95 xset user.dir2 'another xattr' foo
96 xset user.dir3 'this is one last one for the moment' foo
97
98 xset user.dir4 'another dir test' foo/bar
99 xset user.dir5 'one last one' foo/bar
100
101 xset user.foo 'new foo' foo/file3 foo/bar/file5
102 xset user.bar 'new bar' foo/file3 foo/bar/file5
103 xset user.long 'this is also a long attribute that will be truncated in the initial data send' foo/file3 foo/bar/file5
104 xset $RUSR.equal 'this long attribute should remain the same and not need to be transferred' foo/file3 foo/bar/file5
105
106 xset user.dir0 'old extra value' "$chkdir/foo"
107 xset user.dir1 'old dir value' "$chkdir/foo"
108
109 xset user.short 'old short' "$chkdir/file1"
110 xset user.extra 'remove me' "$chkdir/file1"
111
112 xset user.foo 'old foo' "$chkdir/foo/file3"
113 xset $RUSR.equal 'this long attribute should remain the same and not need to be transferred' "$chkdir/foo/file3"
114
115 case $0 in
116 *hlink*)
117     ln foo/bar/file5 foo/bar/file6 || test_skipped "Can't create hardlink"
118     files="$files foo/bar/file6"
119     dashH='-H'
120     altDest='--link-dest'
121     ;;
122 *)
123     dashH=''
124     altDest='--copy-dest'
125     ;;
126 esac
127
128 xls $dirs $files >"$scratchdir/xattrs.txt"
129
130 XFILT='-f-x_system.* -f-x_security.*'
131
132 # OK, let's try a simple xattr copy.
133 checkit "$RSYNC -avX $XFILT $dashH --super . '$chkdir/'" "$fromdir" "$chkdir"
134
135 cd "$chkdir"
136 xls $dirs $files | diff $diffopt "$scratchdir/xattrs.txt" -
137
138 cd "$fromdir"
139
140 if [ "$dashH" ]; then
141     for fn in $files; do
142         name=`basename $fn`
143         ln $fn ../lnk/$name
144     done
145 fi
146
147 checkit "$RSYNC -aiX $XFILT $dashH --super $altDest=../chk . ../to" "$fromdir" "$todir"
148
149 cd "$todir"
150 xls $dirs $files | diff $diffopt "$scratchdir/xattrs.txt" -
151
152 [ "$dashH" ] && rm -rf "$lnkdir"
153
154 cd "$fromdir"
155 rm -rf "$todir"
156
157 xset user.nice 'this is nice, but different' file1
158
159 xls $dirs $files >"$scratchdir/xattrs.txt"
160
161 checkit "$RSYNC -aiX $XFILT $dashH --fake-super --link-dest=../chk . ../to" "$chkdir" "$todir"
162
163 cd "$todir"
164 xls $dirs $files | diff $diffopt "$scratchdir/xattrs.txt" -
165
166 sed -n -e '/^[^d ][^ ]*  *[^ ][^ ]*  *[^ ][^ ]*  *1 /p' "$scratchdir/ls-to" >"$scratchdir/ls-diff-all"
167 fgrep -v './file1' "$scratchdir/ls-diff-all" >"$scratchdir/ls-diff" || :
168 if [ -s "$scratchdir/ls-diff" ]; then
169     echo "Missing hard links on:"
170     cat "$scratchdir/ls-diff"
171     exit 1
172 fi
173 if [ ! -s "$scratchdir/ls-diff-all" ]; then
174     echo "Too many hard links on file1!"
175     exit 1
176 fi
177
178 cd "$chkdir"
179 chmod go-rwx . $dirs $files
180
181 xset user.nice 'this is nice, but different' file1
182 xset $RSYNC_PREFIX.%stat "40000 0,0 $uid_gid" $dirs
183 xset $RSYNC_PREFIX.%stat "100000 0,0 $uid_gid" $files
184
185 xls $dirs $files >"$scratchdir/xattrs.txt"
186
187 cd "$fromdir"
188 rm -rf "$todir"
189
190 # When run by a non-root tester, this checks if no-user-perm files/dirs can be copied.
191 checkit "$RSYNC -aiX $XFILT $dashH --fake-super --chmod=a= . ../to" "$chkdir" "$todir" # 2>"$scratchdir/errors.txt"
192
193 cd "$todir"
194 xls $dirs $files | diff $diffopt "$scratchdir/xattrs.txt" -
195
196 cd "$fromdir"
197 rm -rf "$todir" "$chkdir"
198
199 $RSYNC -aX file1 file2
200 $RSYNC -aX file1 file2 ../chk/
201 $RSYNC -aX --del ../chk/ .
202 $RSYNC -aX file1 ../lnk/
203 [ "$dashH" ] && ln "$chkdir/file1" ../lnk/extra-link
204
205 xls file1 file2 >"$scratchdir/xattrs.txt"
206
207 checkit "$RSYNC -aiiX $XFILT $dashH $altDest=../lnk . ../to" "$chkdir" "$todir"
208
209 [ "$dashH" ] && rm ../lnk/extra-link
210
211 cd "$todir"
212 xls file1 file2 | diff $diffopt "$scratchdir/xattrs.txt" -
213
214 cd "$fromdir"
215 rm "$todir/file2"
216
217 echo extra >file1
218 $RSYNC -aX . ../chk/
219
220 checkit "$RSYNC -aiiX $XFILT . ../to" "$chkdir" "$todir"
221
222 cd "$todir"
223 xls file1 file2 | diff $diffopt "$scratchdir/xattrs.txt" -
224
225 # The script would have aborted on error, so getting here means we've won.
226 exit 0