[Midnightbsd-cvs] src [11184] add x flag to rm
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Jun 30 19:40:36 EDT 2018
Revision: 11184
http://svnweb.midnightbsd.org/src/?rev=11184
Author: laffer1
Date: 2018-06-30 19:40:36 -0400 (Sat, 30 Jun 2018)
Log Message:
-----------
add x flag to rm
Modified Paths:
--------------
trunk/bin/rm/rm.1
trunk/bin/rm/rm.c
Property Changed:
----------------
trunk/bin/rm/rm.1
Modified: trunk/bin/rm/rm.1
===================================================================
--- trunk/bin/rm/rm.1 2018-06-30 23:39:19 UTC (rev 11183)
+++ trunk/bin/rm/rm.1 2018-06-30 23:40:36 UTC (rev 11184)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\"-
.\" Copyright (c) 1990, 1993, 1994
.\" The Regents of the University of California. All rights reserved.
@@ -30,10 +31,9 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)rm.1 8.5 (Berkeley) 12/5/94
-.\" $FreeBSD: src/bin/rm/rm.1,v 1.36.2.1 2005/10/08 17:27:37 dougb Exp $
-.\" $MidnightBSD: src/bin/rm/rm.1,v 1.4 2007/07/26 20:13:00 laffer1 Exp $
+.\" $FreeBSD: stable/10/bin/rm/rm.1 290634 2015-11-10 07:17:38Z bapt $
.\"
-.Dd October 31, 2010
+.Dd November 7, 2015
.Dt RM 1
.Os
.Sh NAME
@@ -43,7 +43,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl f | i
-.Op Fl dIPRrvW
+.Op Fl dIPRrvWx
.Ar
.Nm unlink
.Ar file
@@ -133,6 +133,8 @@
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
@@ -194,6 +196,19 @@
is specified with
.Fl f
the file will be overwritten and removed even if it has hard links.
+.Sh EXAMPLES
+Recursively remove all files contained within the
+.Pa foobar
+directory hierarchy:
+.Pp
+.Dl $ rm -rf foobar
+.Pp
+Either of these commands will remove the file
+.Pa -f :
+.Bd -literal -offset indent
+$ rm -- -f
+$ rm ./-f
+.Ed
.Sh COMPATIBILITY
The
.Nm
@@ -221,7 +236,7 @@
The
.Nm
command conforms to
-.St -p1003.2 .
+.St -p1003.1-2013 .
.Pp
The simplified
.Nm unlink
Property changes on: trunk/bin/rm/rm.1
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/bin/rm/rm.c
===================================================================
--- trunk/bin/rm/rm.c 2018-06-30 23:39:19 UTC (rev 11183)
+++ trunk/bin/rm/rm.c 2018-06-30 23:40:36 UTC (rev 11184)
@@ -40,7 +40,7 @@
#endif /* not lint */
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/bin/rm/rm.c,v 1.52.2.1 2005/10/08 17:27:37 dougb Exp $");
+__FBSDID("$FreeBSD: stable/10/bin/rm/rm.c 290634 2015-11-10 07:17:38Z bapt $");
#include <sys/stat.h>
#include <sys/param.h>
@@ -51,7 +51,9 @@
#include <fcntl.h>
#include <fts.h>
#include <grp.h>
+#include <locale.h>
#include <pwd.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -58,10 +60,10 @@
#include <sysexits.h>
#include <unistd.h>
-int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok;
-int rflag, Iflag;
-uid_t uid;
-volatile sig_atomic_t info;
+static int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok;
+static int rflag, Iflag, xflag;
+static uid_t uid;
+static volatile sig_atomic_t info;
static int check(const char *, const char *, struct stat *);
static int check2(char **);
@@ -86,6 +88,8 @@
int ch;
char *p;
+ (void)setlocale(LC_ALL, "");
+
/*
* Test for the special case where the utility is called as
* "unlink", for which the functionality provided is greatly
@@ -106,8 +110,8 @@
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 +140,9 @@
case 'W':
Wflag = 1;
break;
+ case 'x':
+ xflag = 1;
+ break;
default:
usage();
}
@@ -149,8 +156,7 @@
}
checkdot(argv);
- if (getenv("POSIXLY_CORRECT") == NULL)
- checkslash(argv);
+ checkslash(argv);
uid = geteuid();
(void)signal(SIGINFO, siginfo);
@@ -196,6 +202,8 @@
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;
@@ -330,12 +338,12 @@
warn("%s", p->fts_path);
eval = 1;
}
- if (errno)
+ if (!fflag && errno)
err(1, "fts_read");
fts_close(fts);
}
-void
+static void
rm_file(char **argv)
{
struct stat sb;
@@ -412,7 +420,7 @@
* System V file system). In a logging or COW file system, you'll have to
* have kernel support.
*/
-int
+static int
rm_overwrite(const char *file, struct stat *sbp)
{
struct stat sb, sb2;
@@ -430,8 +438,8 @@
if (!S_ISREG(sbp->st_mode))
return (1);
if (sbp->st_nlink > 1 && !fflag) {
- warnx("%s (inode %u): not overwritten due to multiple links",
- file, sbp->st_ino);
+ warnx("%s (inode %ju): not overwritten due to multiple links",
+ file, (uintmax_t)sbp->st_ino);
return (0);
}
if ((fd = open(file, O_WRONLY|O_NONBLOCK|O_NOFOLLOW, 0)) == -1)
@@ -624,7 +632,7 @@
{
(void)fprintf(stderr, "%s\n%s\n",
- "usage: rm [-f | -i] [-dIPRrvW] file ...",
+ "usage: rm [-f | -i] [-dIPRrvWx] file ...",
" unlink file");
exit(EX_USAGE);
}
More information about the Midnightbsd-cvs
mailing list