Add some more tests to ensure that renaming a file to a directory and a

directory to a file fails with the appropriate error codes.  tmpfs still
fails these tests, but the fix is almost ready to go in.
This commit is contained in:
jmmv 2007-07-23 15:05:43 +00:00
parent 2189caca89
commit 12f24779d1
2 changed files with 34 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: h_tools.c,v 1.7 2006/11/09 16:20:06 jmmv Exp $ */
/* $NetBSD: h_tools.c,v 1.8 2007/07/23 15:05:43 jmmv Exp $ */
/*
* Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
@ -216,7 +216,12 @@ rename_main(int argc, char **argv)
if (argc < 3)
return EXIT_FAILURE;
return rename(argv[1], argv[2]);
if (rename(argv[1], argv[2]) == -1) {
perror("rename");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/* --------------------------------------------------------------------- */

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# $NetBSD: t_rename,v 1.6 2007/07/23 12:51:35 jmmv Exp $
# $NetBSD: t_rename,v 1.7 2007/07/23 15:05:43 jmmv Exp $
#
# Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
# All rights reserved.
@ -54,7 +54,7 @@ test_run() {
test_name "Cross device renames do not work"
mkdir a || die
${Src_Dir}/h_tools rename a /var/tmp/a && die
${Src_Dir}/h_tools rename a /var/tmp/a >/dev/null 2>&1 && die
rmdir a || die
test_name "Directories can be renamed"
@ -105,23 +105,24 @@ test_run() {
test -f b || die
rm b
test_name "Rename to a override an empty directory works"
test_name "Rename a directory to a override an empty directory works"
mkdir a || die
touch a/c || die
mkdir b || die
${Src_Dir}/h_tools rename a b || die
${Src_Dir}/h_tools rename a b >/dev/null 2>&1 || die
test -e a && die
test -d b || die
test -f b/c || die
rm b/c
rmdir b
test_name "Rename to a override a non-empty directory fails"
test_name "Rename a directory to a override a non-empty directory fails"
mkdir a || die
touch a/c || die
mkdir b || die
touch b/d || die
${Src_Dir}/h_tools rename a b && die
err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
echo ${err} | grep 'Directory not empty' >/dev/null || die
test -d a || die
test -f a/c || die
test -d b || die
@ -131,6 +132,26 @@ test_run() {
rmdir a
rmdir b
test_name "Rename a directory to a override a file fails"
mkdir a || die
touch b || die
err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
echo ${err} | grep 'Not a directory' >/dev/null || die
test -d a || die
test -f b || die
rmdir a
rm b
test_name "Rename a file to a override a directory fails"
touch a || die
mkdir b || die
err=$(${Src_Dir}/h_tools rename a b 2>&1) && die
echo ${err} | grep 'Is a directory' >/dev/null || die
test -f a || die
test -d b || die
rm a
rmdir b
mkdir dir || die
touch dir/a
echo 'mv dir/a dir/b' | kqueue_monitor 2 dir dir/a || die