|
1 #!/bin/sh |
|
2 # |
|
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
4 # |
|
5 # Copyright 2019 Olaf Wintermann. All rights reserved. |
|
6 # |
|
7 # Redistribution and use in source and binary forms, with or without |
|
8 # modification, are permitted provided that the following conditions are met: |
|
9 # |
|
10 # 1. Redistributions of source code must retain the above copyright |
|
11 # notice, this list of conditions and the following disclaimer. |
|
12 # |
|
13 # 2. Redistributions in binary form must reproduce the above copyright |
|
14 # notice, this list of conditions and the following disclaimer in the |
|
15 # documentation and/or other materials provided with the distribution. |
|
16 # |
|
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 # POSSIBILITY OF SUCH DAMAGE. |
|
28 # |
|
29 |
|
30 if [ -z "$DAV_BIN" ]; |
|
31 then |
|
32 echo "DAV_BIN variable not set" |
|
33 exit 1 |
|
34 fi |
|
35 if [ -z "$DAV_SYNC_BIN" ]; |
|
36 then |
|
37 echo "DAV_BIN variable not set" |
|
38 exit 1 |
|
39 fi |
|
40 |
|
41 XATTR=../../build/xattrtool |
|
42 |
|
43 # checks if tmp-sync/out.txt contains a specific text |
|
44 # arg1: pattern |
|
45 # arg2: errormsg |
|
46 check_tmpout() |
|
47 { |
|
48 TEST=`cat tmp-sync/out.txt | grep "$1"` |
|
49 if [ $? -ne 0 ]; |
|
50 then |
|
51 echo "$2" |
|
52 exit 2 |
|
53 fi |
|
54 } |
|
55 |
|
56 # do dav-sync push and check return value |
|
57 # arg1: dir |
|
58 # arg2: errormsg |
|
59 dav_sync_push() |
|
60 { |
|
61 $DAV_SYNC_BIN push $1 > tmp-sync/out.txt |
|
62 if [ $? -ne 0 ]; |
|
63 then |
|
64 echo "$2" |
|
65 exit 2 |
|
66 fi |
|
67 } |
|
68 # do dav-sync pull and check return value |
|
69 # arg1: dir |
|
70 # arg2: errormsg |
|
71 dav_sync_pull() |
|
72 { |
|
73 $DAV_SYNC_BIN pull $1 > tmp-sync/out.txt |
|
74 if [ $? -ne 0 ]; |
|
75 then |
|
76 echo "$2" |
|
77 exit 2 |
|
78 fi |
|
79 } |
|
80 |
|
81 rm -f .dav/dav-sync-tests-test4a-db.xml |
|
82 rm -f .dav/dav-sync-tests-test4b-db.xml |
|
83 |
|
84 $DAV_BIN rm dav-test-repo/sync/test4 2> /dev/null |
|
85 |
|
86 $DAV_BIN mkcol dav-test-repo/sync/test4 2> /dev/null |
|
87 |
|
88 # tmp sync dir |
|
89 rm -Rf tmp-sync |
|
90 mkdir tmp-sync |
|
91 mkdir tmp-sync/test4a |
|
92 mkdir tmp-sync/test4b |
|
93 |
|
94 # ---------------------------------------------------------------------------- |
|
95 # test 1: add file with all kinds of metadata and sync |
|
96 # expected result: everything synced |
|
97 |
|
98 mkdir tmp-sync/test4a/dir1 |
|
99 |
|
100 echo "#!/bin/sh" > tmp-sync/test4a/file1 |
|
101 echo "echo file1out" >> tmp-sync/test4a/file1 |
|
102 |
|
103 cp synctest/file2 tmp-sync/test4a/ |
|
104 cp synctest/file3 tmp-sync/test4a/dir1/ |
|
105 cp synctest/file4 tmp-sync/test4a/dir1/ |
|
106 |
|
107 # add tags |
|
108 $DAV_SYNC_BIN add-tag -s test4a tmp-sync/test4a/file1 mytag |
|
109 $DAV_SYNC_BIN add-tag -s test4a tmp-sync/test4a/file1 test1 |
|
110 |
|
111 # add xattr |
|
112 ../../build/xattrtool set tmp-sync/test4a/file1 attr1 testvalue |
|
113 |
|
114 # set mtime |
|
115 touch -t 01011200 tmp-sync/test4a/file1 |
|
116 |
|
117 # +x |
|
118 chmod +x tmp-sync/test4a/file1 |
|
119 |
|
120 dav_sync_push test4a "test 1: push failed" |
|
121 check_tmpout "4 files pushed" "test 1: wrong push counter" |
|
122 check_tmpout "0 conflicts" "test 1: wrong conflict counter (push)" |
|
123 check_tmpout "0 errors" "test 1: wrong error counter (push)" |
|
124 |
|
125 dav_sync_pull test4b "test 1: pull failed" |
|
126 check_tmpout "4 files pulled" "test 1: wrong pull counter" |
|
127 check_tmpout "0 conflicts" "test 1: wrong conflict counter (pull)" |
|
128 check_tmpout "0 errors" "test 1: wrong error counter (pull)" |
|
129 |
|
130 # check metadata |
|
131 MTIMEA1=`stat -c %Y tmp-sync/test4a/file1` |
|
132 MTIMEB1=`stat -c %Y tmp-sync/test4b/file1` |
|
133 |
|
134 if [ "$MTIMEA1" != "$MTIMEB1" ]; then |
|
135 echo "test 1: mtime not synced" |
|
136 exit 2 |
|
137 fi |
|
138 |
|
139 OUT=`tmp-sync/test4b/file1 2> /dev/null` |
|
140 if [ "$OUT" != "file1out" ]; then |
|
141 echo "test 1: not executable" |
|
142 exit 2 |
|
143 fi |
|
144 |
|
145 OUT=`../../build/xattrtool get tmp-sync/test4b/file1 attr1 2> /dev/null` |
|
146 if [ "$OUT" != "testvalue" ]; then |
|
147 echo "test 1: xattr not synced" |
|
148 exit 2 |
|
149 fi |
|
150 |
|
151 TAGS=`$DAV_SYNC_BIN list-tags -s test4b tmp-sync/test4b/file1 > tmp-sync/out.txt 2> /dev/null` |
|
152 if [ $? -ne 0 ]; then |
|
153 echo "test 1: list-tags failed" |
|
154 exit 2 |
|
155 fi |
|
156 check_tmpout "mytag" "test 1: file1: missing tag mytag" |
|
157 check_tmpout "test1" "test 1: file1: missing tag test1" |
|
158 |
|
159 |
|
160 # ---------------------------------------------------------------------------- |
|
161 # test 2: copy file (without xattr and tags) and sync |
|
162 # expected result: WebDAV COPY, but metadata adjusted |
|
163 |
|
164 cp tmp-sync/test4a/file1 tmp-sync/test4a/copy1 |
|
165 |
|
166 ../../xattrtool remove tmp-sync/test4a/copy1 tags > /dev/null 2>&1 |
|
167 ../../xattrtool remove tmp-sync/test4a/copy1 attr1 > /dev/null 2>&1 |
|
168 |
|
169 chmod -x tmp-sync/test4a/copy1 |
|
170 |
|
171 touch tmp-sync/test4a/copy1 |
|
172 |
|
173 dav_sync_push test4a "test 2: push failed" |
|
174 check_tmpout "1 file pushed" "test 2: wrong push counter" |
|
175 check_tmpout "0 conflicts" "test 2: wrong conflict counter (push)" |
|
176 check_tmpout "0 errors" "test 2: wrong error counter (push)" |
|
177 check_tmpout "copy" "test 2: no copy (push)" |
|
178 |
|
179 dav_sync_pull test4b "test 2: pull failed" |
|
180 check_tmpout "1 file pulled" "test 2: wrong pull counter" |
|
181 check_tmpout "0 conflicts" "test 2: wrong conflict counter (pull)" |
|
182 check_tmpout "0 errors" "test 2: wrong error counter (pull)" |
|
183 |
|
184 # check metadata |
|
185 MTIMEA1=`stat -c %Y tmp-sync/test4a/copy1 2> /dev/null` |
|
186 MTIMEB1=`stat -c %Y tmp-sync/test4b/copy1 2> /dev/null` |
|
187 |
|
188 if [ "$MTIMEA1" != "$MTIMEB1" ]; then |
|
189 echo "test 2: mtime not synced" |
|
190 exit 2 |
|
191 fi |
|
192 |
|
193 OUT=`tmp-sync/test4b/copy1 2> /dev/null` |
|
194 if [ $? -eq 0 ]; then |
|
195 echo "test 2: copy1 should be executable" |
|
196 exit 2 |
|
197 fi |
|
198 |
|
199 TAGS=`$DAV_SYNC_BIN list-tags -s test4b tmp-sync/test4b/copy1 > tmp-sync/out.txt 2> /dev/null` |
|
200 if [ $? -ne 0 ]; then |
|
201 echo "test 2: list-tags failed" |
|
202 exit 2 |
|
203 fi |
|
204 LN=`cat tmp-sync/out.txt | wc -l` |
|
205 if [ $LN -ne 0 ]; then |
|
206 echo "test 2: list-tags not empty" |
|
207 exit 2 |
|
208 fi |
|
209 |