1#!/bin/sh 2# 3# $NetBSD: t_rename,v 1.5 2006/11/09 16:20:06 jmmv Exp $ 4# 5# Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. 6# All rights reserved. 7# 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 10# 2005 program. 11# 12# Redistribution and use in source and binary forms, with or without 13# modification, are permitted provided that the following conditions 14# are met: 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. 27# 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. 39# 40# $FreeBSD$ 41# 42 43# 44# Verifies that the rename operation works (either by renaming entries or 45# by moving them). 46# 47 48test_run() { 49 test_mount 50 51 test_name "'.' and '..' entries cannot be renamed" 52 mkdir a || die 53 mv a/. c 2>/dev/null && die 54 mv a/.. c 2>/dev/null && die 55 rmdir a || die 56 57 test_name "Cross device renames do not work" 58 mkdir a || die 59 ${Src_Dir}/h_tools rename a /var/tmp/a && die 60 rmdir a || die 61 62 test_name "Directories can be renamed" 63 mkdir a || die 64 mv a c || die 65 test -d a && die 66 test -d c || die 67 rmdir c || die 68 69 test_name "The '..' entry is updated after moves" 70 mkdir a || die 71 mkdir b || die 72 mv b a || die 73 test -d a/b/../b || die 74 test -d a/b/../../a || die 75 eval $(stat -s a/b) 76 [ ${st_nlink} = 2 ] || die 77 eval $(stat -s a) 78 [ ${st_nlink} = 3 ] || die 79 rmdir a/b || die 80 rmdir a || die 81 82 test_name "The '..' entry is correct after renames" 83 mkdir a || die 84 mkdir b || die 85 mv b a || die 86 mv a c || die 87 test -d c/b/../b || die 88 test -d c/b/../../c || die 89 rmdir c/b || die 90 rmdir c || die 91 92 test_name "The '..' entry is correct after multiple moves" 93 mkdir a || die 94 mkdir b || die 95 mv b a || die 96 mv a c || die 97 mv c/b d || die 98 test -d d/../c || die 99 rmdir d || die 100 rmdir c || die 101 102 test_name "Rename works if the target file exists" 103 touch a || die 104 touch b || die 105 mv a b || die 106 test -f a && die 107 test -f b || die 108 rm b 109 110 mkdir dir || die 111 touch dir/a 112 echo 'mv dir/a dir/b' | kqueue_monitor 2 dir dir/a || die 113 test_name "Renaming a file raises NOTE_RENAME on the old file" 114 kqueue_check dir/a NOTE_RENAME || die 115 test_name "Renaming a file raises NOTE_WRITE on the parent directory" 116 kqueue_check dir NOTE_WRITE || die 117 rm dir/b || die 118 rmdir dir || die 119 120 mkdir dir || die 121 touch dir/a 122 touch dir/b 123 echo 'mv dir/a dir/b' | kqueue_monitor 3 dir dir/a dir/b || die 124 test_name "Renaming a file raises NOTE_RENAME on the old file" 125 kqueue_check dir/a NOTE_RENAME || die 126 test_name "Renaming a file raises NOTE_WRITE on the parent directory" 127 kqueue_check dir NOTE_WRITE || die 128 test_name "Renaming a file raises NOTE_DELETE on the target file" 129 kqueue_check dir/b NOTE_DELETE || die 130 rm dir/b || die 131 rmdir dir || die 132 133 mkdir dir1 || die 134 mkdir dir2 || die 135 touch dir1/a 136 echo 'mv dir1/a dir2/a' | kqueue_monitor 3 dir1 dir1/a dir2 || die 137 test_name "Moving a file raises NOTE_RENAME on the old file" 138 kqueue_check dir1/a NOTE_RENAME || die 139 test_name "Moving a file raises NOTE_WRITE on the source directory" 140 kqueue_check dir1 NOTE_WRITE || die 141 test_name "Moving a file raises NOTE_WRITE on the target directory" 142 kqueue_check dir2 NOTE_WRITE || die 143 rm dir2/a || die 144 rmdir dir1 || die 145 rmdir dir2 || die 146 147 test_unmount 148} 149 150. ${SUBRDIR}/h_funcs.subr 151