add verbose flag
exit(1) --> exit(EX_USAGE) Reviewed by: obrien
This commit is contained in:
parent
e8b91e712a
commit
2e0328a8ba
@ -43,7 +43,7 @@
|
||||
.Nd remove directory entries
|
||||
.Sh SYNOPSIS
|
||||
.Nm rm
|
||||
.Op Fl dfiPRrW
|
||||
.Op Fl dfiPRrWv
|
||||
.Ar file ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
@ -103,6 +103,8 @@ Equivalent to
|
||||
Attempt to undelete the named files.
|
||||
Currently, this option can only be used to recover
|
||||
files covered by whiteouts.
|
||||
.It Fl v
|
||||
Be verbose when deleting files, showing them as they are removed.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
|
33
bin/rm/rm.c
33
bin/rm/rm.c
@ -58,11 +58,12 @@ static const char rcsid[] =
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern char *flags_to_string __P((u_long, char *));
|
||||
|
||||
int dflag, eval, fflag, iflag, Pflag, Wflag, stdin_ok;
|
||||
int dflag, eval, fflag, iflag, Pflag, Wflag, vflag, stdin_ok;
|
||||
uid_t uid;
|
||||
|
||||
int check __P((char *, char *, struct stat *));
|
||||
@ -87,7 +88,7 @@ main(argc, argv)
|
||||
int ch, rflag;
|
||||
|
||||
Pflag = rflag = 0;
|
||||
while ((ch = getopt(argc, argv, "dfiPRrW")) != -1)
|
||||
while ((ch = getopt(argc, argv, "dfiPRrWv")) != -1)
|
||||
switch(ch) {
|
||||
case 'd':
|
||||
dflag = 1;
|
||||
@ -110,6 +111,9 @@ main(argc, argv)
|
||||
case 'W':
|
||||
Wflag = 1;
|
||||
break;
|
||||
case 'v':
|
||||
vflag = 1;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
@ -222,6 +226,7 @@ rm_tree(argv)
|
||||
rval = chflags(p->fts_accpath,
|
||||
p->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE));
|
||||
if (!rval) {
|
||||
int e;
|
||||
/*
|
||||
* If we can't read or search the directory, may still be
|
||||
* able to remove it. Don't print out the un{read,search}able
|
||||
@ -230,23 +235,32 @@ rm_tree(argv)
|
||||
switch (p->fts_info) {
|
||||
case FTS_DP:
|
||||
case FTS_DNR:
|
||||
if (!rmdir(p->fts_accpath) || (fflag && errno == ENOENT))
|
||||
if ((e=rmdir(p->fts_accpath)) || (fflag && errno == ENOENT)) {
|
||||
if (e == 0 && vflag)
|
||||
(void)printf("%s\n", p->fts_accpath);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case FTS_W:
|
||||
if (!undelete(p->fts_accpath) ||
|
||||
(fflag && errno == ENOENT))
|
||||
if (!(e=undelete(p->fts_accpath)) ||
|
||||
(fflag && errno == ENOENT)) {
|
||||
if (e == 0 && vflag)
|
||||
(void)printf("%s\n", p->fts_accpath);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (Pflag)
|
||||
rm_overwrite(p->fts_accpath, NULL);
|
||||
if (!unlink(p->fts_accpath) || (fflag && errno == ENOENT))
|
||||
if (!(e=unlink(p->fts_accpath)) || (fflag && errno == ENOENT)) {
|
||||
if (e == 0 && vflag)
|
||||
(void)printf("%s\n", p->fts_accpath);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
err:
|
||||
warn("%s", p->fts_path);
|
||||
eval = 1;
|
||||
@ -312,6 +326,8 @@ rm_file(argv)
|
||||
warn("%s", f);
|
||||
eval = 1;
|
||||
}
|
||||
if (vflag)
|
||||
(void)printf("%s\n", f);
|
||||
}
|
||||
}
|
||||
|
||||
@ -451,7 +467,6 @@ checkdot(argv)
|
||||
void
|
||||
usage()
|
||||
{
|
||||
|
||||
(void)fprintf(stderr, "usage: rm [-f | -i] [-dPRrW] file ...\n");
|
||||
exit(1);
|
||||
(void)fprintf(stderr, "usage: rm [-f | -i] [-dPRrWv] file ...\n");
|
||||
exit(EX_USAGE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user