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