PR/47770: Eitan Adler: add x flag to rm to avoid cross mount points

This commit is contained in:
christos 2013-04-26 18:43:22 +00:00
parent 9569800454
commit aab67d5210
2 changed files with 19 additions and 9 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: rm.1,v 1.25 2012/10/13 14:18:16 njoly Exp $
.\" $NetBSD: rm.1,v 1.26 2013/04/26 18:43:22 christos Exp $
.\"
.\" Copyright (c) 1990, 1993, 1994, 2003
.\" The Regents of the University of California. All rights reserved.
@ -32,7 +32,7 @@
.\"
.\" @(#)rm.1 8.5 (Berkeley) 12/5/94
.\"
.Dd August 25, 2006
.Dd April 26, 2013
.Dt RM 1
.Os
.Sh NAME
@ -41,7 +41,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl f | Fl i
.Op Fl dPRrvW
.Op Fl dPRrvWx
.Ar
.Sh DESCRIPTION
The
@ -110,6 +110,8 @@ to be verbose, showing files as they are processed.
Attempts to undelete the named files.
Currently, this option can only be used to recover
files covered by whiteouts.
.It Fl x
When removing a hierarchy, do not cross mount points.
.El
.Pp
The
@ -189,7 +191,9 @@ utility is expected to be
compatible.
The
.Fl v
option is an extension.
and
.Fl x
options are extensions.
.Pp
The
.Fl P

View File

@ -1,4 +1,4 @@
/* $NetBSD: rm.c,v 1.52 2012/06/13 07:35:37 dholland Exp $ */
/* $NetBSD: rm.c,v 1.53 2013/04/26 18:43:22 christos Exp $ */
/*-
* Copyright (c) 1990, 1993, 1994, 2003
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\
#if 0
static char sccsid[] = "@(#)rm.c 8.8 (Berkeley) 4/27/95";
#else
__RCSID("$NetBSD: rm.c,v 1.52 2012/06/13 07:35:37 dholland Exp $");
__RCSID("$NetBSD: rm.c,v 1.53 2013/04/26 18:43:22 christos Exp $");
#endif
#endif /* not lint */
@ -61,6 +61,7 @@ __RCSID("$NetBSD: rm.c,v 1.52 2012/06/13 07:35:37 dholland Exp $");
#include <unistd.h>
static int dflag, eval, fflag, iflag, Pflag, stdin_ok, vflag, Wflag;
static int xflag;
static sig_atomic_t pinfo;
static int check(char *, char *, struct stat *);
@ -94,8 +95,8 @@ main(int argc, char *argv[])
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
Pflag = rflag = 0;
while ((ch = getopt(argc, argv, "dfiPRrvW")) != -1)
Pflag = rflag = xflag = 0;
while ((ch = getopt(argc, argv, "dfiPRrvWx")) != -1)
switch (ch) {
case 'd':
dflag = 1;
@ -118,6 +119,9 @@ main(int argc, char *argv[])
case 'v':
vflag = 1;
break;
case 'x':
xflag = 1;
break;
case 'W':
Wflag = 1;
break;
@ -175,6 +179,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)) == NULL)
err(1, "fts_open failed");
while ((p = fts_read(fts)) != NULL) {
@ -591,7 +597,7 @@ static void
usage(void)
{
(void)fprintf(stderr, "usage: %s [-f|-i] [-dPRrvW] file ...\n",
(void)fprintf(stderr, "usage: %s [-f|-i] [-dPRrvWx] file ...\n",
getprogname());
exit(1);
/* NOTREACHED */