1 # $NetBSD: t_rename.sh,v 1.5 2010/11/07 17:51:18 jmmv Exp $
3 # Copyright (c) 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
29 # Verifies that the rename operation works (either by renaming entries or
35 atf_set
"descr" "Tests that '.' and '..' cannot be renamed"
36 atf_set
"require.user" "root"
41 atf_check
-s eq
:0 -o empty
-e empty mkdir a
42 atf_check
-s eq
:1 -o empty
-e ignore
mv a
/. c
43 atf_check
-s eq
:1 -o empty
-e ignore
mv a
/.. c
44 atf_check
-s eq
:0 -o empty
-e empty
rmdir a
49 atf_test_case crossdev
51 atf_set
"descr" "Tests that cross-device renames do not work"
52 atf_set
"require.user" "root"
57 atf_check
-s eq
:0 -o empty
-e empty mkdir a
58 atf_check
-s eq
:1 -o empty
-e save
:stderr \
59 $
(atf_get_srcdir
)/h_tools rename a
/var
/tmp
/a
60 atf_check
-s eq
:0 -o ignore
-e empty
grep "Cross-device link" stderr
61 atf_check
-s eq
:0 -o empty
-e empty
test -d a
62 atf_check
-s eq
:0 -o empty
-e empty
rmdir a
69 atf_set
"descr" "Tests that basic renames work"
70 atf_set
"require.user" "root"
75 atf_check
-s eq
:0 -o empty
-e empty mkdir a
76 atf_check
-s eq
:0 -o empty
-e empty
mv a c
77 atf_check
-s eq
:1 -o empty
-e empty
test -d a
78 atf_check
-s eq
:0 -o empty
-e empty
test -d c
79 atf_check
-s eq
:0 -o empty
-e empty
rmdir c
86 atf_set
"descr" "Tests that the '..' entry is properly updated" \
88 atf_set
"require.user" "root"
93 echo "Checking if the '..' entry is updated after moves"
94 atf_check
-s eq
:0 -o empty
-e empty mkdir a
95 atf_check
-s eq
:0 -o empty
-e empty mkdir b
96 atf_check
-s eq
:0 -o empty
-e empty
mv b a
97 atf_check
-s eq
:0 -o empty
-e empty
test -d a
/b
/..
/b
98 atf_check
-s eq
:0 -o empty
-e empty
test -d a
/b
/..
/..
/a
100 [ ${st_nlink} = 2 ] || atf_fail
"Incorrect number of links"
102 [ ${st_nlink} = 3 ] || atf_fail
"Incorrect number of links"
103 atf_check
-s eq
:0 -o empty
-e empty
rmdir a
/b
104 atf_check
-s eq
:0 -o empty
-e empty
rmdir a
106 echo "Checking if the '..' entry is correct after renames"
107 atf_check
-s eq
:0 -o empty
-e empty mkdir a
108 atf_check
-s eq
:0 -o empty
-e empty mkdir b
109 atf_check
-s eq
:0 -o empty
-e empty
mv b a
110 atf_check
-s eq
:0 -o empty
-e empty
mv a c
111 atf_check
-s eq
:0 -o empty
-e empty
test -d c
/b
/..
/b
112 atf_check
-s eq
:0 -o empty
-e empty
test -d c
/b
/..
/..
/c
113 atf_check
-s eq
:0 -o empty
-e empty
rmdir c
/b
114 atf_check
-s eq
:0 -o empty
-e empty
rmdir c
116 echo "Checking if the '..' entry is correct after multiple moves"
117 atf_check
-s eq
:0 -o empty
-e empty mkdir a
118 atf_check
-s eq
:0 -o empty
-e empty mkdir b
119 atf_check
-s eq
:0 -o empty
-e empty
mv b a
120 atf_check
-s eq
:0 -o empty
-e empty
mv a c
121 atf_check
-s eq
:0 -o empty
-e empty
mv c
/b d
122 atf_check
-s eq
:0 -o empty
-e empty
test -d d
/..
/c
123 atf_check
-s eq
:0 -o empty
-e empty
rmdir d
124 atf_check
-s eq
:0 -o empty
-e empty
rmdir c
129 atf_test_case dir_to_emptydir
130 dir_to_emptydir_head
() {
131 atf_set
"descr" "Tests that renaming a directory to override an" \
132 "empty directory works"
133 atf_set
"require.user" "root"
135 dir_to_emptydir_body
() {
138 atf_check
-s eq
:0 -o empty
-e empty mkdir a
139 atf_check
-s eq
:0 -o empty
-e empty
touch a
/c
140 atf_check
-s eq
:0 -o empty
-e empty mkdir b
141 atf_check
-s eq
:0 -o empty
-e empty \
142 $
(atf_get_srcdir
)/h_tools rename a b
143 atf_check
-s eq
:1 -o empty
-e empty
test -e a
144 atf_check
-s eq
:0 -o empty
-e empty
test -d b
145 atf_check
-s eq
:0 -o empty
-e empty
test -f b
/c
152 atf_test_case dir_to_fulldir
153 dir_to_fulldir_head
() {
154 atf_set
"descr" "Tests that renaming a directory to override a" \
155 "non-empty directory fails"
156 atf_set
"require.user" "root"
158 dir_to_fulldir_body
() {
161 atf_check
-s eq
:0 -o empty
-e empty mkdir a
162 atf_check
-s eq
:0 -o empty
-e empty
touch a
/c
163 atf_check
-s eq
:0 -o empty
-e empty mkdir b
164 atf_check
-s eq
:0 -o empty
-e empty
touch b
/d
165 atf_check
-s eq
:1 -o empty
-e save
:stderr \
166 $
(atf_get_srcdir
)/h_tools rename a b
167 atf_check
-s eq
:0 -o ignore
-e empty
grep "Directory not empty" stderr
168 atf_check
-s eq
:0 -o empty
-e empty
test -d a
169 atf_check
-s eq
:0 -o empty
-e empty
test -f a
/c
170 atf_check
-s eq
:0 -o empty
-e empty
test -d b
171 atf_check
-s eq
:0 -o empty
-e empty
test -f b
/d
180 atf_test_case dir_to_file
182 atf_set
"descr" "Tests that renaming a directory to override a" \
184 atf_set
"require.user" "root"
189 atf_check
-s eq
:0 -o empty
-e empty mkdir a
190 atf_check
-s eq
:0 -o empty
-e empty
touch b
191 atf_check
-s eq
:1 -o empty
-e save
:stderr \
192 $
(atf_get_srcdir
)/h_tools rename a b
193 atf_check
-s eq
:0 -o ignore
-e empty
grep "Not a directory" stderr
194 atf_check
-s eq
:0 -o empty
-e empty
test -d a
195 atf_check
-s eq
:0 -o empty
-e empty
test -f b
202 atf_test_case file_to_dir
204 atf_set
"descr" "Tests that renaming a file to override a" \
206 atf_set
"require.user" "root"
211 atf_check
-s eq
:0 -o empty
-e empty
touch a
212 atf_check
-s eq
:0 -o empty
-e empty mkdir b
213 atf_check
-s eq
:1 -o empty
-e save
:stderr \
214 $
(atf_get_srcdir
)/h_tools rename a b
215 atf_check
-s eq
:0 -o ignore
-e empty
grep "Is a directory" stderr
216 atf_check
-s eq
:0 -o empty
-e empty
test -f a
217 atf_check
-s eq
:0 -o empty
-e empty
test -d b
226 atf_set
"descr" "Tests that moving and renaming files raise the" \
227 "correct kqueue events"
228 atf_set
"require.user" "root"
233 atf_check
-s eq
:0 -o empty
-e empty mkdir dir
234 atf_check
-s eq
:0 -o empty
-e empty
touch dir
/a
235 echo 'mv dir/a dir/b' | kqueue_monitor
2 dir dir
/a
236 kqueue_check dir
/a NOTE_RENAME
237 kqueue_check dir NOTE_WRITE
238 atf_check
-s eq
:0 -o empty
-e empty
rm dir
/b
239 atf_check
-s eq
:0 -o empty
-e empty
rmdir dir
241 atf_check
-s eq
:0 -o empty
-e empty mkdir dir
242 atf_check
-s eq
:0 -o empty
-e empty
touch dir
/a
243 atf_check
-s eq
:0 -o empty
-e empty
touch dir
/b
244 echo 'mv dir/a dir/b' | kqueue_monitor
3 dir dir
/a dir
/b
245 kqueue_check dir
/a NOTE_RENAME
246 kqueue_check dir NOTE_WRITE
247 kqueue_check dir
/b NOTE_DELETE
248 atf_check
-s eq
:0 -o empty
-e empty
rm dir
/b
249 atf_check
-s eq
:0 -o empty
-e empty
rmdir dir
251 atf_check
-s eq
:0 -o empty
-e empty mkdir dir1
252 atf_check
-s eq
:0 -o empty
-e empty mkdir dir2
253 atf_check
-s eq
:0 -o empty
-e empty
touch dir
1/a
254 echo 'mv dir1/a dir2/a' | kqueue_monitor
3 dir1 dir
1/a dir2
255 kqueue_check dir
1/a NOTE_RENAME
256 kqueue_check dir1 NOTE_WRITE
257 kqueue_check dir2 NOTE_WRITE
258 atf_check
-s eq
:0 -o empty
-e empty
rm dir
2/a
259 atf_check
-s eq
:0 -o empty
-e empty
rmdir dir1
260 atf_check
-s eq
:0 -o empty
-e empty
rmdir dir2
265 atf_init_test_cases
() {
266 . $
(atf_get_srcdir
)/..
/h_funcs.subr
267 . $
(atf_get_srcdir
)/h_funcs.subr
269 atf_add_test_case dots
270 atf_add_test_case crossdev
271 atf_add_test_case basic
272 atf_add_test_case dotdot
273 atf_add_test_case dir_to_emptydir
274 atf_add_test_case dir_to_fulldir
275 atf_add_test_case dir_to_file
276 atf_add_test_case file_to_dir
277 atf_add_test_case kqueue