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.
21 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
37 # Verifies that the rename operation works (either by renaming entries or
44 test_name "'.' and '..' entries cannot be renamed"
46 mv a/. c 2>/dev/null && die
47 mv a/.. c 2>/dev/null && die
50 test_name "Cross device renames do not work"
52 ${Src_Dir}/h_tools rename a /var/tmp/a >/dev/null 2>&1 && die
55 test_name "Directories can be renamed"
62 test_name "The '..' entry is updated after moves"
66 test -d a/b/../b || die
67 test -d a/b/../../a || die
69 [ ${st_nlink} = 2 ] || die
71 [ ${st_nlink} = 3 ] || die
75 test_name "The '..' entry is correct after renames"
80 test -d c/b/../b || die
81 test -d c/b/../../c || die
85 test_name "The '..' entry is correct after multiple moves"
95 test_name "Rename works if the target file exists"
103 test_name "Rename a directory to a override an empty directory works"
107 ${Src_Dir}/h_tools rename a b >/dev/null 2>&1 || die
114 test_name "Rename a directory to a override a non-empty directory fails"
119 err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
120 echo ${err} | grep 'Directory not empty' >/dev/null || die
130 test_name "Rename a directory to a override a file fails"
133 err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
134 echo ${err} | grep 'Not a directory' >/dev/null || die
140 test_name "Rename a file to a override a directory fails"
143 err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
144 echo ${err} | grep 'Is a directory' >/dev/null || die
152 echo 'mv dir/a dir/b' | kqueue_monitor 2 dir dir/a || die
153 test_name "Renaming a file raises NOTE_RENAME on the old file"
154 kqueue_check dir/a NOTE_RENAME || die
155 test_name "Renaming a file raises NOTE_WRITE on the parent directory"
156 kqueue_check dir NOTE_WRITE || die
163 echo 'mv dir/a dir/b' | kqueue_monitor 3 dir dir/a dir/b || die
164 test_name "Renaming a file raises NOTE_RENAME on the old file"
165 kqueue_check dir/a NOTE_RENAME || die
166 test_name "Renaming a file raises NOTE_WRITE on the parent directory"
167 kqueue_check dir NOTE_WRITE || die
168 test_name "Renaming a file raises NOTE_DELETE on the target file"
169 kqueue_check dir/b NOTE_DELETE || die
176 echo 'mv dir1/a dir2/a' | kqueue_monitor 3 dir1 dir1/a dir2 || die
177 test_name "Moving a file raises NOTE_RENAME on the old file"
178 kqueue_check dir1/a NOTE_RENAME || die
179 test_name "Moving a file raises NOTE_WRITE on the source directory"
180 kqueue_check dir1 NOTE_WRITE || die
181 test_name "Moving a file raises NOTE_WRITE on the target directory"
182 kqueue_check dir2 NOTE_WRITE || die
190 . ${SUBRDIR}/h_funcs.subr