From 12f24779d1b2e2af6bd3675a80cb58fda760d307 Mon Sep 17 00:00:00 2001 From: jmmv Date: Mon, 23 Jul 2007 15:05:43 +0000 Subject: [PATCH] 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. --- regress/sys/fs/tmpfs/h_tools.c | 9 +++++++-- regress/sys/fs/tmpfs/t_rename | 33 +++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/regress/sys/fs/tmpfs/h_tools.c b/regress/sys/fs/tmpfs/h_tools.c index 5b065bdc8d3d..813ab581fa0c 100644 --- a/regress/sys/fs/tmpfs/h_tools.c +++ b/regress/sys/fs/tmpfs/h_tools.c @@ -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; } /* --------------------------------------------------------------------- */ diff --git a/regress/sys/fs/tmpfs/t_rename b/regress/sys/fs/tmpfs/t_rename index ffd3e09f68b0..99a8906bc682 100755 --- a/regress/sys/fs/tmpfs/t_rename +++ b/regress/sys/fs/tmpfs/t_rename @@ -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