Patch for bug #1183: Added a -xdev option to find (configurable)
authorRobert Griebl <griebl@gmx.de>
Wed, 24 Jul 2002 00:34:48 +0000 (00:34 -0000)
committerRobert Griebl <griebl@gmx.de>
Wed, 24 Jul 2002 00:34:48 +0000 (00:34 -0000)
findutils/config.in
findutils/find.c

index 770d75245eeb0a28c80d03816f19a3107ee54ada..d5a3714d21966f103826be06f1ac77d531fef3e6 100644 (file)
@@ -11,6 +11,7 @@ if [ "$CONFIG_FIND" = "y" ] ; then
     bool '  Enable modified time matching (-mtime) option' CONFIG_FEATURE_FIND_MTIME
     bool '  Enable permissions matching (-perm) option' CONFIG_FEATURE_FIND_PERM
     bool '  Enable filetype matching (-type) option' CONFIG_FEATURE_FIND_TYPE
+    bool '  Enable stay in filesystem (-xdev) option' CONFIG_FEATURE_FIND_XDEV
 fi
 bool 'grep'        CONFIG_GREP
 if [ "$CONFIG_GREP" = "y" ] ; then
index 0ff0893a6c2437c027c866399ea0f39a23a0d006..dd02206e3051886dfb8956446b21ea6fa85af7fc 100644 (file)
@@ -51,6 +51,12 @@ static char mtime_char;
 static int mtime_days;
 #endif
 
+#ifdef CONFIG_FEATURE_FIND_XDEV
+static dev_t *xdev_dev;
+static int xdev_count = 0;
+#endif
+
+
 static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
 {
        if (pattern != NULL) {
@@ -88,6 +94,22 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
                        goto no_match;
        }
 #endif
+#ifdef CONFIG_FEATURE_FIND_XDEV
+       if (xdev_count) {
+               int i;
+               for (i=0; i<xdev_count; i++) {
+                       if (xdev_dev[i] == statbuf-> st_dev)
+                               break;
+               }
+               if (i == xdev_count) {
+                       if(S_ISDIR(statbuf->st_mode))
+                               return SKIP;
+                       else
+                               goto no_match;
+               }
+       }
+#endif
+
        puts(fileName);
 no_match:
        return (TRUE);
@@ -179,6 +201,27 @@ int find_main(int argc, char **argv)
                                error_msg_and_die("invalid argument `%s' to `-mtime'", argv[i]);
                        if ((mtime_char = argv[i][0]) == '-')
                                mtime_days = -mtime_days;
+#endif
+#ifdef CONFIG_FEATURE_FIND_XDEV
+               } else if (strcmp(argv[i], "-xdev") == 0) {
+                       struct stat stbuf;
+
+                       xdev_count = ( firstopt - 1 ) ? ( firstopt - 1 ) : 1;
+                       xdev_dev = xmalloc ( xdev_count * sizeof( dev_t ));
+
+                       if ( firstopt == 1 ) {
+                               if ( stat ( ".", &stbuf ) < 0 )
+                                       error_msg_and_die("could not stat '.'" );
+                               xdev_dev [0] = stbuf. st_dev;
+                       }
+                       else {
+                       
+                               for (i = 1; i < firstopt; i++) {
+                                       if ( stat ( argv [i], &stbuf ) < 0 )
+                                               error_msg_and_die("could not stat '%s'", argv [i] );
+                                       xdev_dev [i-1] = stbuf. st_dev;
+                               }
+                       }                                               
 #endif
                } else
                        show_usage();