On 26 April 2013 14:30, Eitan Adler <[email protected]> wrote:
> The attached patch adds an "x" option to rm(1) to avoid cross
> filesystem boundaries.
> This has been committed to DragonFlyBSD and FreeBSD.  It has been
> submitted to NetBSD as well.

Inline:

Index: rm.c
===================================================================
RCS file: /cvs/src/bin/rm/rm.c,v
retrieving revision 1.27
diff -u -r1.27 rm.c
--- rm.c        5 Sep 2012 19:49:08 -0000       1.27
+++ rm.c        26 Apr 2013 18:27:24 -0000
@@ -50,6 +50,7 @@
 extern char *__progname;

 int dflag, eval, fflag, iflag, Pflag, stdin_ok;
+static int xflag;

 int    check(char *, char *, struct stat *);
 void   checkdot(char **);
@@ -73,8 +74,8 @@

        setlocale(LC_ALL, "");

-       Pflag = rflag = 0;
-       while ((ch = getopt(argc, argv, "dfiPRr")) != -1)
+       Pflag = rflag = xflag = 0;
+       while ((ch = getopt(argc, argv, "dfiPRrx")) != -1)
                switch(ch) {
                case 'd':
                        dflag = 1;
@@ -94,6 +95,9 @@
                case 'r':                       /* Compatibility. */
                        rflag = 1;
                        break;
+               case 'x':
+                       xflag = 1;
+                       break;
                default:
                        usage();
                }
@@ -140,6 +144,8 @@
        flags = FTS_PHYSICAL;
        if (!needstat)
                flags |= FTS_NOSTAT;
+       if (xflag)
+               flags |= FTS_XDEV;
        if (!(fts = fts_open(argv, flags, NULL)))
                err(1, NULL);
        while ((p = fts_read(fts)) != NULL) {
@@ -414,6 +420,6 @@
 void
 usage(void)
 {
-       (void)fprintf(stderr, "usage: %s [-dfiPRr] file ...\n", __progname);
+       (void)fprintf(stderr, "usage: %s [-dfiPRrx] file ...\n", __progname);
        exit(1);
 }
Index: rm.1
===================================================================
RCS file: /cvs/src/bin/rm/rm.1,v
retrieving revision 1.36
diff -u -r1.36 rm.1
--- rm.1        5 Sep 2012 06:21:18 -0000       1.36
+++ rm.1        26 Apr 2013 18:27:24 -0000
@@ -95,6 +95,8 @@
 .It Fl r
 Equivalent to
 .Fl R .
+.It Fl x
+When removing a hierarchy, do not cross mount points.
 .El
 .Pp
 The


-- 
Eitan Adler

Reply via email to