3 # $NetBSD: t_rename,v 1.7 2007/07/23 15:05:43 jmmv Exp $
5 # Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
8 # This code is derived from software contributed to The NetBSD Foundation
9 # by Julio M. Merino Vidal, developed as part of Google's Summer of Code
12 # Redistribution and use in source and binary forms, with or without
13 # modification, are permitted provided that the following conditions
15 # 1. Redistributions of source code must retain the above copyright
16 # notice, this list of conditions and the following disclaimer.
17 # 2. Redistributions in binary form must reproduce the above copyright
18 # notice, this list of conditions and the following disclaimer in the
19 # documentation and/or other materials provided with the distribution.
20 # 3. All advertising materials mentioning features or use of this software
21 # must display the following acknowledgement:
22 # This product includes software developed by the NetBSD
23 # Foundation, Inc. and its contributors.
24 # 4. Neither the name of The NetBSD Foundation nor the names of its
25 # contributors may be used to endorse or promote products derived
26 # from this software without specific prior written permission.
28 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 # POSSIBILITY OF SUCH DAMAGE.
44 # Verifies that the rename operation works (either by renaming entries or
51 test_name "'.' and '..' entries cannot be renamed"
53 mv a/. c 2>/dev/null && die
54 mv a/.. c 2>/dev/null && die
57 test_name "Cross device renames do not work"
59 ${Src_Dir}/h_tools rename a /var/tmp/a >/dev/null 2>&1 && die
62 test_name "Directories can be renamed"
69 test_name "The '..' entry is updated after moves"
73 test -d a/b/../b || die
74 test -d a/b/../../a || die
76 [ ${st_nlink} = 2 ] || die
78 [ ${st_nlink} = 3 ] || die
82 test_name "The '..' entry is correct after renames"
87 test -d c/b/../b || die
88 test -d c/b/../../c || die
92 test_name "The '..' entry is correct after multiple moves"
102 test_name "Rename works if the target file exists"
110 test_name "Rename a directory to a override an empty directory works"
114 ${Src_Dir}/h_tools rename a b >/dev/null 2>&1 || die
121 test_name "Rename a directory to a override a non-empty directory fails"
126 err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
127 echo ${err} | grep 'Directory not empty' >/dev/null || die
137 test_name "Rename a directory to a override a file fails"
140 err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
141 echo ${err} | grep 'Not a directory' >/dev/null || die
147 test_name "Rename a file to a override a directory fails"
150 err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
151 echo ${err} | grep 'Is a directory' >/dev/null || die
159 echo 'mv dir/a dir/b' | kqueue_monitor 2 dir dir/a || die
160 test_name "Renaming a file raises NOTE_RENAME on the old file"
161 kqueue_check dir/a NOTE_RENAME || die
162 test_name "Renaming a file raises NOTE_WRITE on the parent directory"
163 kqueue_check dir NOTE_WRITE || die
170 echo 'mv dir/a dir/b' | kqueue_monitor 3 dir dir/a dir/b || die
171 test_name "Renaming a file raises NOTE_RENAME on the old file"
172 kqueue_check dir/a NOTE_RENAME || die
173 test_name "Renaming a file raises NOTE_WRITE on the parent directory"
174 kqueue_check dir NOTE_WRITE || die
175 test_name "Renaming a file raises NOTE_DELETE on the target file"
176 kqueue_check dir/b NOTE_DELETE || die
183 echo 'mv dir1/a dir2/a' | kqueue_monitor 3 dir1 dir1/a dir2 || die
184 test_name "Moving a file raises NOTE_RENAME on the old file"
185 kqueue_check dir1/a NOTE_RENAME || die
186 test_name "Moving a file raises NOTE_WRITE on the source directory"
187 kqueue_check dir1 NOTE_WRITE || die
188 test_name "Moving a file raises NOTE_WRITE on the target directory"
189 kqueue_check dir2 NOTE_WRITE || die
197 . ${SUBRDIR}/h_funcs.subr