Add -x option to avoid crossing mount points when removing a hierarchy.

Discussed on:	-hackers
Inspired by:	DragonflyBSD
MFC After:	1 week
This commit is contained in:
eadler 2013-04-26 17:45:37 +00:00
parent 594af1b98e
commit d2cd9ce7fa
2 changed files with 13 additions and 6 deletions

View File

@ -32,7 +32,7 @@
.\" @(#)rm.1 8.5 (Berkeley) 12/5/94
.\" $FreeBSD$
.\"
.Dd March 15, 2013
.Dd April 25, 2013
.Dt RM 1
.Os
.Sh NAME
@ -42,7 +42,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl f | i
.Op Fl dIPRrvW
.Op Fl dIPRrvWx
.Ar
.Nm unlink
.Ar file
@ -132,6 +132,8 @@ Attempt to undelete the named files.
Currently, this option can only be used to recover
files covered by whiteouts in a union file system (see
.Xr undelete 2 ) .
.It Fl x
When removing a hierarchy, do not cross mount points.
.El
.Pp
The

View File

@ -59,7 +59,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
static int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok;
static int rflag, Iflag;
static int rflag, Iflag, xflag;
static uid_t uid;
static volatile sig_atomic_t info;
@ -106,8 +106,8 @@ main(int argc, char *argv[])
exit(eval);
}
Pflag = rflag = 0;
while ((ch = getopt(argc, argv, "dfiIPRrvW")) != -1)
Pflag = rflag = xflag = 0;
while ((ch = getopt(argc, argv, "dfiIPRrvWx")) != -1)
switch(ch) {
case 'd':
dflag = 1;
@ -136,6 +136,9 @@ main(int argc, char *argv[])
case 'W':
Wflag = 1;
break;
case 'x':
xflag = 1;
break;
default:
usage();
}
@ -196,6 +199,8 @@ rm_tree(char **argv)
flags |= FTS_NOSTAT;
if (Wflag)
flags |= FTS_WHITEOUT;
if (xflag)
flags |= FTS_XDEV;
if (!(fts = fts_open(argv, flags, NULL))) {
if (fflag && errno == ENOENT)
return;
@ -624,7 +629,7 @@ usage(void)
{
(void)fprintf(stderr, "%s\n%s\n",
"usage: rm [-f | -i] [-dIPRrvW] file ...",
"usage: rm [-f | -i] [-dIPRrvWx] file ...",
" unlink file");
exit(EX_USAGE);
}