~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to src/rm.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* `rm' file deletion utility for GNU.
2
 
   Copyright (C) 1988, 1990-1991, 1994-2011 Free Software Foundation, Inc.
 
1
/* 'rm' file deletion utility for GNU.
 
2
   Copyright (C) 1988-2012 Free Software Foundation, Inc.
3
3
 
4
4
   This program is free software: you can redistribute it and/or modify
5
5
   it under the terms of the GNU General Public License as published by
34
34
#include "yesno.h"
35
35
#include "priv-set.h"
36
36
 
37
 
/* The official name of this program (e.g., no `g' prefix).  */
 
37
/* The official name of this program (e.g., no 'g' prefix).  */
38
38
#define PROGRAM_NAME "rm"
39
39
 
40
40
#define AUTHORS \
77
77
  {"-presume-input-tty", no_argument, NULL, PRESUME_INPUT_TTY_OPTION},
78
78
 
79
79
  {"recursive", no_argument, NULL, 'r'},
 
80
  {"dir", no_argument, NULL, 'd'},
80
81
  {"verbose", no_argument, NULL, 'v'},
81
82
  {GETOPT_HELP_OPTION_DECL},
82
83
  {GETOPT_VERSION_OPTION_DECL},
98
99
ARGMATCH_VERIFY (interactive_args, interactive_types);
99
100
 
100
101
/* Advise the user about invalid usages like "rm -foo" if the file
101
 
   "-foo" exists, assuming ARGC and ARGV are as with `main'.  */
 
102
   "-foo" exists, assuming ARGC and ARGV are as with 'main'.  */
102
103
 
103
104
static void
104
105
diagnose_leading_hyphen (int argc, char **argv)
115
116
      if (arg[0] == '-' && arg[1] && lstat (arg, &st) == 0)
116
117
        {
117
118
          fprintf (stderr,
118
 
                   _("Try `%s ./%s' to remove the file %s.\n"),
 
119
                   _("Try '%s ./%s' to remove the file %s.\n"),
119
120
                   argv[0],
120
121
                   quotearg_n_style (1, shell_quoting_style, arg),
121
122
                   quote (arg));
128
129
usage (int status)
129
130
{
130
131
  if (status != EXIT_SUCCESS)
131
 
    fprintf (stderr, _("Try `%s --help' for more information.\n"),
132
 
             program_name);
 
132
    emit_try_help ();
133
133
  else
134
134
    {
135
135
      printf (_("Usage: %s [OPTION]... FILE...\n"), program_name);
136
136
      fputs (_("\
137
137
Remove (unlink) the FILE(s).\n\
138
138
\n\
139
 
  -f, --force           ignore nonexistent files, never prompt\n\
 
139
  -f, --force           ignore nonexistent files and arguments, never prompt\n\
140
140
  -i                    prompt before every removal\n\
141
141
"), stdout);
142
142
      fputs (_("\
152
152
                          that of the corresponding command line argument\n\
153
153
"), stdout);
154
154
      fputs (_("\
155
 
      --no-preserve-root  do not treat `/' specially\n\
156
 
      --preserve-root   do not remove `/' (default)\n\
 
155
      --no-preserve-root  do not treat '/' specially\n\
 
156
      --preserve-root   do not remove '/' (default)\n\
157
157
  -r, -R, --recursive   remove directories and their contents recursively\n\
 
158
  -d, --dir             remove empty directories\n\
158
159
  -v, --verbose         explain what is being done\n\
159
160
"), stdout);
160
161
      fputs (HELP_OPTION_DESCRIPTION, stdout);
166
167
"), stdout);
167
168
      printf (_("\
168
169
\n\
169
 
To remove a file whose name starts with a `-', for example `-foo',\n\
 
170
To remove a file whose name starts with a '-', for example '-foo',\n\
170
171
use one of these commands:\n\
171
172
  %s -- -foo\n\
172
173
\n\
190
191
  x->ignore_missing_files = false;
191
192
  x->interactive = RMI_SOMETIMES;
192
193
  x->one_file_system = false;
 
194
  x->remove_empty_directories = false;
193
195
  x->recursive = false;
194
196
  x->root_dev_ino = NULL;
195
197
  x->stdin_tty = isatty (STDIN_FILENO);
196
198
  x->verbose = false;
197
199
 
198
 
  /* Since this program exits immediately after calling `rm', rm need not
 
200
  /* Since this program exits immediately after calling 'rm', rm need not
199
201
     expend unnecessary effort to preserve the initial working directory.  */
200
202
  x->require_restore_cwd = false;
201
203
}
221
223
  /* Try to disable the ability to unlink a directory.  */
222
224
  priv_set_remove_linkdir ();
223
225
 
224
 
  while ((c = getopt_long (argc, argv, "firvIR", long_opts, NULL)) != -1)
 
226
  while ((c = getopt_long (argc, argv, "dfirvIR", long_opts, NULL)) != -1)
225
227
    {
226
228
      switch (c)
227
229
        {
 
230
        case 'd':
 
231
          x.remove_empty_directories = true;
 
232
          break;
 
233
 
228
234
        case 'f':
229
235
          x.interactive = RMI_NEVER;
230
236
          x.ignore_missing_files = true;