add verbose flag

exit(1) --> exit(EX_USAGE)

Reviewed by:	obrien
This commit is contained in:
mharo 1999-08-29 02:20:26 +00:00
parent e8b91e712a
commit 2e0328a8ba
2 changed files with 27 additions and 10 deletions

View File

@ -43,7 +43,7 @@
.Nd remove directory entries .Nd remove directory entries
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm rm .Nm rm
.Op Fl dfiPRrW .Op Fl dfiPRrWv
.Ar file ... .Ar file ...
.Sh DESCRIPTION .Sh DESCRIPTION
The The
@ -103,6 +103,8 @@ Equivalent to
Attempt to undelete the named files. Attempt to undelete the named files.
Currently, this option can only be used to recover Currently, this option can only be used to recover
files covered by whiteouts. files covered by whiteouts.
.It Fl v
Be verbose when deleting files, showing them as they are removed.
.El .El
.Pp .Pp
The The

View File

@ -58,11 +58,12 @@ static const char rcsid[] =
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sysexits.h>
#include <unistd.h> #include <unistd.h>
extern char *flags_to_string __P((u_long, char *)); 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; uid_t uid;
int check __P((char *, char *, struct stat *)); int check __P((char *, char *, struct stat *));
@ -87,7 +88,7 @@ main(argc, argv)
int ch, rflag; int ch, rflag;
Pflag = rflag = 0; Pflag = rflag = 0;
while ((ch = getopt(argc, argv, "dfiPRrW")) != -1) while ((ch = getopt(argc, argv, "dfiPRrWv")) != -1)
switch(ch) { switch(ch) {
case 'd': case 'd':
dflag = 1; dflag = 1;
@ -110,6 +111,9 @@ main(argc, argv)
case 'W': case 'W':
Wflag = 1; Wflag = 1;
break; break;
case 'v':
vflag = 1;
break;
default: default:
usage(); usage();
} }
@ -222,6 +226,7 @@ rm_tree(argv)
rval = chflags(p->fts_accpath, rval = chflags(p->fts_accpath,
p->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE)); p->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE));
if (!rval) { if (!rval) {
int e;
/* /*
* If we can't read or search the directory, may still be * 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 * able to remove it. Don't print out the un{read,search}able
@ -230,21 +235,30 @@ rm_tree(argv)
switch (p->fts_info) { switch (p->fts_info) {
case FTS_DP: case FTS_DP:
case FTS_DNR: 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; continue;
}
break; break;
case FTS_W: case FTS_W:
if (!undelete(p->fts_accpath) || if (!(e=undelete(p->fts_accpath)) ||
(fflag && errno == ENOENT)) (fflag && errno == ENOENT)) {
if (e == 0 && vflag)
(void)printf("%s\n", p->fts_accpath);
continue; continue;
}
break; break;
default: default:
if (Pflag) if (Pflag)
rm_overwrite(p->fts_accpath, NULL); 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; continue;
}
} }
} }
err: err:
@ -312,6 +326,8 @@ rm_file(argv)
warn("%s", f); warn("%s", f);
eval = 1; eval = 1;
} }
if (vflag)
(void)printf("%s\n", f);
} }
} }
@ -451,7 +467,6 @@ checkdot(argv)
void void
usage() usage()
{ {
(void)fprintf(stderr, "usage: rm [-f | -i] [-dPRrWv] file ...\n");
(void)fprintf(stderr, "usage: rm [-f | -i] [-dPRrW] file ...\n"); exit(EX_USAGE);
exit(1);
} }