t_rename.sh revision 1.1.4.2 1 1.1.4.2 matt # $NetBSD: t_rename.sh,v 1.1.4.2 2008/01/09 01:59:20 matt Exp $
2 1.1.4.2 matt #
3 1.1.4.2 matt # Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
4 1.1.4.2 matt # All rights reserved.
5 1.1.4.2 matt #
6 1.1.4.2 matt # Redistribution and use in source and binary forms, with or without
7 1.1.4.2 matt # modification, are permitted provided that the following conditions
8 1.1.4.2 matt # are met:
9 1.1.4.2 matt # 1. Redistributions of source code must retain the above copyright
10 1.1.4.2 matt # notice, this list of conditions and the following disclaimer.
11 1.1.4.2 matt # 2. Redistributions in binary form must reproduce the above copyright
12 1.1.4.2 matt # notice, this list of conditions and the following disclaimer in the
13 1.1.4.2 matt # documentation and/or other materials provided with the distribution.
14 1.1.4.2 matt # 3. All advertising materials mentioning features or use of this software
15 1.1.4.2 matt # must display the following acknowledgement:
16 1.1.4.2 matt # This product includes software developed by the NetBSD
17 1.1.4.2 matt # Foundation, Inc. and its contributors.
18 1.1.4.2 matt # 4. Neither the name of The NetBSD Foundation nor the names of its
19 1.1.4.2 matt # contributors may be used to endorse or promote products derived
20 1.1.4.2 matt # from this software without specific prior written permission.
21 1.1.4.2 matt #
22 1.1.4.2 matt # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 1.1.4.2 matt # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 1.1.4.2 matt # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.1.4.2 matt # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 1.1.4.2 matt # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.1.4.2 matt # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.1.4.2 matt # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.1.4.2 matt # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.1.4.2 matt # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.1.4.2 matt # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.1.4.2 matt # POSSIBILITY OF SUCH DAMAGE.
33 1.1.4.2 matt #
34 1.1.4.2 matt
35 1.1.4.2 matt #
36 1.1.4.2 matt # Verifies that the rename operation works (either by renaming entries or
37 1.1.4.2 matt # by moving them).
38 1.1.4.2 matt #
39 1.1.4.2 matt
40 1.1.4.2 matt atf_test_case dots
41 1.1.4.2 matt dots_head() {
42 1.1.4.2 matt atf_set "descr" "Tests that '.' and '..' cannot be renamed"
43 1.1.4.2 matt atf_set "require.user" "root"
44 1.1.4.2 matt }
45 1.1.4.2 matt dots_body() {
46 1.1.4.2 matt test_mount
47 1.1.4.2 matt
48 1.1.4.2 matt atf_check 'mkdir a' 0 null null
49 1.1.4.2 matt atf_check 'mv a/. c' 1 null ignore
50 1.1.4.2 matt atf_check 'mv a/.. c' 1 null ignore
51 1.1.4.2 matt atf_check 'rmdir a' 0 null null
52 1.1.4.2 matt
53 1.1.4.2 matt test_unmount
54 1.1.4.2 matt }
55 1.1.4.2 matt
56 1.1.4.2 matt atf_test_case crossdev
57 1.1.4.2 matt crossdev_head() {
58 1.1.4.2 matt atf_set "descr" "Tests that cross-device renames do not work"
59 1.1.4.2 matt atf_set "require.user" "root"
60 1.1.4.2 matt }
61 1.1.4.2 matt crossdev_body() {
62 1.1.4.2 matt test_mount
63 1.1.4.2 matt
64 1.1.4.2 matt atf_check 'mkdir a' 0 null null
65 1.1.4.2 matt atf_check '$(atf_get_srcdir)/h_tools rename a /var/tmp/a' \
66 1.1.4.2 matt 1 null stderr
67 1.1.4.2 matt atf_check 'grep "Cross-device link" ../stderr' 0 ignore null
68 1.1.4.2 matt atf_check 'test -d a' 0 null null
69 1.1.4.2 matt atf_check 'rmdir a' 0 null null
70 1.1.4.2 matt
71 1.1.4.2 matt test_unmount
72 1.1.4.2 matt }
73 1.1.4.2 matt
74 1.1.4.2 matt atf_test_case basic
75 1.1.4.2 matt basic_head() {
76 1.1.4.2 matt atf_set "descr" "Tests that basic renames work"
77 1.1.4.2 matt atf_set "require.user" "root"
78 1.1.4.2 matt }
79 1.1.4.2 matt basic_body() {
80 1.1.4.2 matt test_mount
81 1.1.4.2 matt
82 1.1.4.2 matt atf_check 'mkdir a' 0 null null
83 1.1.4.2 matt atf_check 'mv a c' 0 null null
84 1.1.4.2 matt atf_check 'test -d a' 1 null null
85 1.1.4.2 matt atf_check 'test -d c' 0 null null
86 1.1.4.2 matt atf_check 'rmdir c' 0 null null
87 1.1.4.2 matt
88 1.1.4.2 matt test_unmount
89 1.1.4.2 matt }
90 1.1.4.2 matt
91 1.1.4.2 matt atf_test_case dotdot
92 1.1.4.2 matt dotdot_head() {
93 1.1.4.2 matt atf_set "descr" "Tests that the '..' entry is properly updated" \
94 1.1.4.2 matt "during moves"
95 1.1.4.2 matt atf_set "require.user" "root"
96 1.1.4.2 matt }
97 1.1.4.2 matt dotdot_body() {
98 1.1.4.2 matt test_mount
99 1.1.4.2 matt
100 1.1.4.2 matt echo "Checking if the '..' entry is updated after moves"
101 1.1.4.2 matt atf_check 'mkdir a' 0 null null
102 1.1.4.2 matt atf_check 'mkdir b' 0 null null
103 1.1.4.2 matt atf_check 'mv b a' 0 null null
104 1.1.4.2 matt atf_check 'test -d a/b/../b' 0 null null
105 1.1.4.2 matt atf_check 'test -d a/b/../../a' 0 null null
106 1.1.4.2 matt eval $(stat -s a/b)
107 1.1.4.2 matt [ ${st_nlink} = 2 ] || atf_fail "Incorrect number of links"
108 1.1.4.2 matt eval $(stat -s a)
109 1.1.4.2 matt [ ${st_nlink} = 3 ] || atf_fail "Incorrect number of links"
110 1.1.4.2 matt atf_check 'rmdir a/b' 0 null null
111 1.1.4.2 matt atf_check 'rmdir a' 0 null null
112 1.1.4.2 matt
113 1.1.4.2 matt echo "Checking if the '..' entry is correct after renames"
114 1.1.4.2 matt atf_check 'mkdir a' 0 null null
115 1.1.4.2 matt atf_check 'mkdir b' 0 null null
116 1.1.4.2 matt atf_check 'mv b a' 0 null null
117 1.1.4.2 matt atf_check 'mv a c' 0 null null
118 1.1.4.2 matt atf_check 'test -d c/b/../b' 0 null null
119 1.1.4.2 matt atf_check 'test -d c/b/../../c' 0 null null
120 1.1.4.2 matt atf_check 'rmdir c/b' 0 null null
121 1.1.4.2 matt atf_check 'rmdir c' 0 null null
122 1.1.4.2 matt
123 1.1.4.2 matt echo "Checking if the '..' entry is correct after multiple moves"
124 1.1.4.2 matt atf_check 'mkdir a' 0 null null
125 1.1.4.2 matt atf_check 'mkdir b' 0 null null
126 1.1.4.2 matt atf_check 'mv b a' 0 null null
127 1.1.4.2 matt atf_check 'mv a c' 0 null null
128 1.1.4.2 matt atf_check 'mv c/b d' 0 null null
129 1.1.4.2 matt atf_check 'test -d d/../c' 0 null null
130 1.1.4.2 matt atf_check 'rmdir d' 0 null null
131 1.1.4.2 matt atf_check 'rmdir c' 0 null null
132 1.1.4.2 matt
133 1.1.4.2 matt test_unmount
134 1.1.4.2 matt }
135 1.1.4.2 matt
136 1.1.4.2 matt atf_test_case dir_to_emptydir
137 1.1.4.2 matt dir_to_emptydir_head() {
138 1.1.4.2 matt atf_set "descr" "Tests that renaming a directory to override an" \
139 1.1.4.2 matt "empty directory works"
140 1.1.4.2 matt atf_set "require.user" "root"
141 1.1.4.2 matt }
142 1.1.4.2 matt dir_to_emptydir_body() {
143 1.1.4.2 matt test_mount
144 1.1.4.2 matt
145 1.1.4.2 matt atf_check 'mkdir a' 0 null null
146 1.1.4.2 matt atf_check 'touch a/c' 0 null null
147 1.1.4.2 matt atf_check 'mkdir b' 0 null null
148 1.1.4.2 matt atf_check '$(atf_get_srcdir)/h_tools rename a b' 0 null null
149 1.1.4.2 matt atf_check 'test -e a' 1 null null
150 1.1.4.2 matt atf_check 'test -d b' 0 null null
151 1.1.4.2 matt atf_check 'test -f b/c' 0 null null
152 1.1.4.2 matt rm b/c
153 1.1.4.2 matt rmdir b
154 1.1.4.2 matt
155 1.1.4.2 matt test_unmount
156 1.1.4.2 matt }
157 1.1.4.2 matt
158 1.1.4.2 matt atf_test_case dir_to_fulldir
159 1.1.4.2 matt dir_to_fulldir_head() {
160 1.1.4.2 matt atf_set "descr" "Tests that renaming a directory to override a" \
161 1.1.4.2 matt "non-empty directory fails"
162 1.1.4.2 matt atf_set "require.user" "root"
163 1.1.4.2 matt }
164 1.1.4.2 matt dir_to_fulldir_body() {
165 1.1.4.2 matt test_mount
166 1.1.4.2 matt
167 1.1.4.2 matt atf_check 'mkdir a' 0 null null
168 1.1.4.2 matt atf_check 'touch a/c' 0 null null
169 1.1.4.2 matt atf_check 'mkdir b' 0 null null
170 1.1.4.2 matt atf_check 'touch b/d' 0 null null
171 1.1.4.2 matt atf_check '$(atf_get_srcdir)/h_tools rename a b' 1 null stderr
172 1.1.4.2 matt atf_check 'grep "Directory not empty" ../stderr' 0 ignore null
173 1.1.4.2 matt atf_check 'test -d a' 0 null null
174 1.1.4.2 matt atf_check 'test -f a/c' 0 null null
175 1.1.4.2 matt atf_check 'test -d b' 0 null null
176 1.1.4.2 matt atf_check 'test -f b/d' 0 null null
177 1.1.4.2 matt rm a/c
178 1.1.4.2 matt rm b/d
179 1.1.4.2 matt rmdir a
180 1.1.4.2 matt rmdir b
181 1.1.4.2 matt
182 1.1.4.2 matt test_unmount
183 1.1.4.2 matt }
184 1.1.4.2 matt
185 1.1.4.2 matt atf_test_case dir_to_file
186 1.1.4.2 matt dir_to_file_head() {
187 1.1.4.2 matt atf_set "descr" "Tests that renaming a directory to override a" \
188 1.1.4.2 matt "file fails"
189 1.1.4.2 matt atf_set "require.user" "root"
190 1.1.4.2 matt }
191 1.1.4.2 matt dir_to_file_body() {
192 1.1.4.2 matt test_mount
193 1.1.4.2 matt
194 1.1.4.2 matt atf_check 'mkdir a' 0 null null
195 1.1.4.2 matt atf_check 'touch b' 0 null null
196 1.1.4.2 matt atf_check '$(atf_get_srcdir)/h_tools rename a b' 1 null stderr
197 1.1.4.2 matt atf_check 'grep "Not a directory" ../stderr' 0 ignore null
198 1.1.4.2 matt atf_check 'test -d a' 0 null null
199 1.1.4.2 matt atf_check 'test -f b' 0 null null
200 1.1.4.2 matt rmdir a
201 1.1.4.2 matt rm b
202 1.1.4.2 matt
203 1.1.4.2 matt test_unmount
204 1.1.4.2 matt }
205 1.1.4.2 matt
206 1.1.4.2 matt atf_test_case file_to_dir
207 1.1.4.2 matt file_to_dir_head() {
208 1.1.4.2 matt atf_set "descr" "Tests that renaming a file to override a" \
209 1.1.4.2 matt "directory fails"
210 1.1.4.2 matt atf_set "require.user" "root"
211 1.1.4.2 matt }
212 1.1.4.2 matt file_to_dir_body() {
213 1.1.4.2 matt test_mount
214 1.1.4.2 matt
215 1.1.4.2 matt atf_check 'touch a' 0 null null
216 1.1.4.2 matt atf_check 'mkdir b' 0 null null
217 1.1.4.2 matt atf_check '$(atf_get_srcdir)/h_tools rename a b' 1 null stderr
218 1.1.4.2 matt atf_check 'grep "Is a directory" ../stderr' 0 ignore null
219 1.1.4.2 matt atf_check 'test -f a' 0 null null
220 1.1.4.2 matt atf_check 'test -d b' 0 null null
221 1.1.4.2 matt rm a
222 1.1.4.2 matt rmdir b
223 1.1.4.2 matt
224 1.1.4.2 matt test_unmount
225 1.1.4.2 matt }
226 1.1.4.2 matt
227 1.1.4.2 matt atf_test_case kqueue
228 1.1.4.2 matt kqueue_head() {
229 1.1.4.2 matt atf_set "descr" "Tests that moving and renaming files raise the" \
230 1.1.4.2 matt "correct kqueue events"
231 1.1.4.2 matt atf_set "require.user" "root"
232 1.1.4.2 matt }
233 1.1.4.2 matt kqueue_body() {
234 1.1.4.2 matt test_mount
235 1.1.4.2 matt
236 1.1.4.2 matt atf_check 'mkdir dir' 0 null null
237 1.1.4.2 matt atf_check 'touch dir/a' 0 null null
238 1.1.4.2 matt echo 'mv dir/a dir/b' | kqueue_monitor 2 dir dir/a
239 1.1.4.2 matt kqueue_check dir/a NOTE_RENAME
240 1.1.4.2 matt kqueue_check dir NOTE_WRITE
241 1.1.4.2 matt atf_check 'rm dir/b' 0 null null
242 1.1.4.2 matt atf_check 'rmdir dir' 0 null null
243 1.1.4.2 matt
244 1.1.4.2 matt atf_check 'mkdir dir' 0 null null
245 1.1.4.2 matt atf_check 'touch dir/a' 0 null null
246 1.1.4.2 matt atf_check 'touch dir/b' 0 null null
247 1.1.4.2 matt echo 'mv dir/a dir/b' | kqueue_monitor 3 dir dir/a dir/b
248 1.1.4.2 matt kqueue_check dir/a NOTE_RENAME
249 1.1.4.2 matt kqueue_check dir NOTE_WRITE
250 1.1.4.2 matt kqueue_check dir/b NOTE_DELETE
251 1.1.4.2 matt atf_check 'rm dir/b' 0 null null
252 1.1.4.2 matt atf_check 'rmdir dir' 0 null null
253 1.1.4.2 matt
254 1.1.4.2 matt atf_check 'mkdir dir1' 0 null null
255 1.1.4.2 matt atf_check 'mkdir dir2' 0 null null
256 1.1.4.2 matt atf_check 'touch dir1/a' 0 null null
257 1.1.4.2 matt echo 'mv dir1/a dir2/a' | kqueue_monitor 3 dir1 dir1/a dir2
258 1.1.4.2 matt kqueue_check dir1/a NOTE_RENAME
259 1.1.4.2 matt kqueue_check dir1 NOTE_WRITE
260 1.1.4.2 matt kqueue_check dir2 NOTE_WRITE
261 1.1.4.2 matt atf_check 'rm dir2/a' 0 null null
262 1.1.4.2 matt atf_check 'rmdir dir1' 0 null null
263 1.1.4.2 matt atf_check 'rmdir dir2' 0 null null
264 1.1.4.2 matt
265 1.1.4.2 matt test_unmount
266 1.1.4.2 matt }
267 1.1.4.2 matt
268 1.1.4.2 matt atf_init_test_cases() {
269 1.1.4.2 matt . $(atf_get_srcdir)/../h_funcs.subr
270 1.1.4.2 matt . $(atf_get_srcdir)/h_funcs.subr
271 1.1.4.2 matt
272 1.1.4.2 matt atf_add_test_case dots
273 1.1.4.2 matt atf_add_test_case crossdev
274 1.1.4.2 matt atf_add_test_case basic
275 1.1.4.2 matt atf_add_test_case dotdot
276 1.1.4.2 matt atf_add_test_case dir_to_emptydir
277 1.1.4.2 matt atf_add_test_case dir_to_fulldir
278 1.1.4.2 matt atf_add_test_case dir_to_file
279 1.1.4.2 matt atf_add_test_case file_to_dir
280 1.1.4.2 matt atf_add_test_case kqueue
281 1.1.4.2 matt }
282