summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-01-17 17:02:40 +0100
committerJim Meyering <jim@meyering.net>2007-01-17 17:15:20 +0100
commit0928c2414ab21682600e6572bc628a405fb1ea80 (patch)
treeff030e34af21eb8a8252af6773e54848e18df05b /src
parentd1ad73e0bf6a1b6c62e424c1f28cf344fca10600 (diff)
downloadcoreutils-0928c2414ab21682600e6572bc628a405fb1ea80.tar.xz
Make "rm --interactive=never ..." never prompt.
* NEWS: Mention this. * src/remove.h (enum rm_interactive): New ternary type. (struct rm_options) [interactive]: Use it, here -- rather than bool. * src/remove.c (prompt): Reflect type change. * src/mv.c (rm_option_init): Initialize to RMI_NEVER now. * src/rm.c (main): Add a FIXME comment for '-d' option. Adapt to type change of rm_options.interactive. * tests/rm/i-never: New file. Test for the above fix. * tests/rm/Makefile.am (TESTS): Add i-never.
Diffstat (limited to 'src')
-rw-r--r--src/mv.c4
-rw-r--r--src/remove.c10
-rw-r--r--src/remove.h13
-rw-r--r--src/rm.c18
4 files changed, 29 insertions, 16 deletions
diff --git a/src/mv.c b/src/mv.c
index 03e96e5a0..1d1dddab8 100644
--- a/src/mv.c
+++ b/src/mv.c
@@ -1,5 +1,5 @@
/* mv -- move or rename files
- Copyright (C) 86, 89, 90, 91, 1995-2006 Free Software Foundation, Inc.
+ Copyright (C) 86, 89, 90, 91, 1995-2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -98,7 +98,7 @@ rm_option_init (struct rm_options *x)
/* Should we prompt for removal, too? No. Prompting for the `move'
part is enough. It implies removal. */
- x->interactive = 0;
+ x->interactive = RMI_NEVER;
x->stdin_tty = false;
x->verbose = false;
diff --git a/src/remove.c b/src/remove.c
index fbe720456..97184eb26 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -798,10 +798,14 @@ prompt (int fd_cwd, Dirstack_state const *ds, char const *filename,
*is_empty = T_UNKNOWN;
- if (((!x->ignore_missing_files & (x->interactive | x->stdin_tty))
+ if (x->interactive == RMI_NEVER)
+ return RM_OK;
+
+ if (((!x->ignore_missing_files & ((x->interactive == RMI_ALWAYS)
+ | x->stdin_tty))
&& (write_protected = write_protected_non_symlink (fd_cwd, filename,
ds, sbuf)))
- || x->interactive)
+ || x->interactive == RMI_ALWAYS)
{
if (cache_fstatat (fd_cwd, filename, sbuf, AT_SYMLINK_NOFOLLOW) != 0)
{
@@ -821,7 +825,7 @@ prompt (int fd_cwd, Dirstack_state const *ds, char const *filename,
/* Using permissions doesn't make sense for symlinks. */
if (S_ISLNK (sbuf->st_mode))
{
- if ( ! x->interactive)
+ if (x->interactive != RMI_ALWAYS)
return RM_OK;
write_protected = false;
}
diff --git a/src/remove.h b/src/remove.h
index 2dc617618..ae01e3c6c 100644
--- a/src/remove.h
+++ b/src/remove.h
@@ -1,6 +1,6 @@
/* Remove directory entries.
- Copyright (C) 1998, 2000, 2002, 2003, 2004, 2005, 2006 Free
+ Copyright (C) 1998, 2000, 2002, 2003, 2004, 2005, 2006, 2007 Free
Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
@@ -22,13 +22,22 @@
# include "dev-ino.h"
+enum rm_interactive
+{
+ /* Start with any number larger than 1, so that any legacy tests
+ against values of 0 or 1 will fail. */
+ RMI_ALWAYS = 3,
+ RMI_SOMETIMES,
+ RMI_NEVER
+};
+
struct rm_options
{
/* If true, ignore nonexistent files. */
bool ignore_missing_files;
/* If true, query the user about whether to remove each file. */
- bool interactive;
+ enum rm_interactive interactive;
/* If true, do not traverse into (or remove) any directory that is
on a file system (i.e., that has a different device number) other
diff --git a/src/rm.c b/src/rm.c
index 364a21cf5..81f81ec7f 100644
--- a/src/rm.c
+++ b/src/rm.c
@@ -1,5 +1,5 @@
/* `rm' file deletion utility for GNU.
- Copyright (C) 88, 90, 91, 1994-2006 Free Software Foundation, Inc.
+ Copyright (C) 88, 90, 91, 1994-2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -213,7 +213,7 @@ static void
rm_option_init (struct rm_options *x)
{
x->ignore_missing_files = false;
- x->interactive = false;
+ x->interactive = RMI_SOMETIMES;
x->one_file_system = false;
x->recursive = false;
x->root_dev_ino = NULL;
@@ -249,25 +249,25 @@ main (int argc, char **argv)
{
case 'd':
/* Ignore this option, for backward compatibility with
- coreutils 5.92. Some time after 2005, we'll change this
+ coreutils 5.92. FIXME: Some time after 2005, change this
to report an error (or perhaps behave like FreeBSD does)
instead of ignoring the option. */
break;
case 'f':
- x.interactive = false;
+ x.interactive = RMI_NEVER;
x.ignore_missing_files = true;
prompt_once = false;
break;
case 'i':
- x.interactive = true;
+ x.interactive = RMI_ALWAYS;
x.ignore_missing_files = false;
prompt_once = false;
break;
case 'I':
- x.interactive = false;
+ x.interactive = RMI_NEVER;
x.ignore_missing_files = false;
prompt_once = true;
break;
@@ -288,18 +288,18 @@ main (int argc, char **argv)
switch (i)
{
case interactive_never:
- x.interactive = false;
+ x.interactive = RMI_NEVER;
prompt_once = false;
break;
case interactive_once:
- x.interactive = false;
+ x.interactive = RMI_SOMETIMES;
x.ignore_missing_files = false;
prompt_once = true;
break;
case interactive_always:
- x.interactive = true;
+ x.interactive = RMI_ALWAYS;
x.ignore_missing_files = false;
prompt_once = false;
break;