patch: find -xdev still descends other devs

Paul Fox pgf at brightstareng.com
Fri Mar 24 21:00:33 UTC 2006


because of the ordering of the code, directories that should
be skipped due to -xdev are still traversed.

as a bonus, the new code is smaller.
$ size findutils/find.o.new
   text    data     bss     dec     hex filename
   2384      16      52    2452     994 findutils/find.o
$ size findutils/find.o.orig
   text    data     bss     dec     hex filename
   2447      16      52    2515     9d3 findutils/find.o


i'll commit this unless someone objects.

paul

Index: findutils/find.c
===================================================================
--- findutils/find.c	(revision 14650)
+++ findutils/find.c	(working copy)
@@ -79,6 +79,15 @@
 
 static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
 {
+#ifdef CONFIG_FEATURE_FIND_XDEV
+	if (S_ISDIR(statbuf->st_mode) && xdev_count) {
+		int i;
+		for (i=0; i<xdev_count; i++) {
+			if (xdev_dev[i] != statbuf->st_dev)
+				return SKIP;
+		}
+	}
+#endif
 	if (pattern != NULL) {
 		const char *tmp = strrchr(fileName, '/');
 
@@ -125,21 +134,6 @@
 			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
 #ifdef CONFIG_FEATURE_FIND_NEWER
 	if (newer_mtime != 0) {
 		time_t file_age = newer_mtime - statbuf->st_mtime;

=---------------------
 paul fox, pgf at brightstareng.com



More information about the busybox mailing list