aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-01-10 02:33:02 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-01-10 02:33:02 +0100
commitce9b97f18bfdd594013dec330e05310125d2ef8d (patch)
treeb0f13e14d7e2db0a3e8b354337cab17b155881b9
parent8ced1e5dc55b972addafb91e4c4f527d41b8ee8e (diff)
downloadbusybox-w32-ce9b97f18bfdd594013dec330e05310125d2ef8d.tar.gz
busybox-w32-ce9b97f18bfdd594013dec330e05310125d2ef8d.tar.bz2
busybox-w32-ce9b97f18bfdd594013dec330e05310125d2ef8d.zip
find: correct handling of -xdev
function old new delta find_main 467 448 -19 fileAction 1336 1311 -25 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/find.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/findutils/find.c b/findutils/find.c
index f0c259833..b417123f6 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -407,17 +407,33 @@ static int FAST_FUNC fileAction(const char *fileName,
407 void *userData IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM), 407 void *userData IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM),
408 int depth IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM)) 408 int depth IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM))
409{ 409{
410 int i; 410 int r;
411#if ENABLE_FEATURE_FIND_MAXDEPTH 411#if ENABLE_FEATURE_FIND_MAXDEPTH
412#define minmaxdepth ((int*)userData) 412#define minmaxdepth ((int*)userData)
413 413
414 if (depth < minmaxdepth[0]) return TRUE; 414 if (depth < minmaxdepth[0])
415 if (depth > minmaxdepth[1]) return SKIP; 415 return TRUE; /* skip this, continue recursing */
416 if (depth > minmaxdepth[1])
417 return SKIP; /* stop recursing */
416#endif 418#endif
417 419
420 r = exec_actions(G.actions, fileName, statbuf);
421 /* Had no explicit -print[0] or -exec? then print */
422 if ((r & TRUE) && G.need_print)
423 puts(fileName);
424
425#if ENABLE_FEATURE_FIND_MAXDEPTH
426 if (S_ISDIR(statbuf->st_mode)) {
427 if (depth == minmaxdepth[1])
428 return SKIP;
429 }
430#endif
418#if ENABLE_FEATURE_FIND_XDEV 431#if ENABLE_FEATURE_FIND_XDEV
432 /* -xdev stops on mountpoints, but AFTER mountpoit itself
433 * is processed as usual */
419 if (S_ISDIR(statbuf->st_mode)) { 434 if (S_ISDIR(statbuf->st_mode)) {
420 if (G.xdev_count) { 435 if (G.xdev_count) {
436 int i;
421 for (i = 0; i < G.xdev_count; i++) { 437 for (i = 0; i < G.xdev_count; i++) {
422 if (G.xdev_dev[i] == statbuf->st_dev) 438 if (G.xdev_dev[i] == statbuf->st_dev)
423 goto found; 439 goto found;
@@ -427,19 +443,10 @@ static int FAST_FUNC fileAction(const char *fileName,
427 } 443 }
428 } 444 }
429#endif 445#endif
430 i = exec_actions(G.actions, fileName, statbuf);
431 /* Had no explicit -print[0] or -exec? then print */
432 if ((i & TRUE) && G.need_print)
433 puts(fileName);
434 446
435#if ENABLE_FEATURE_FIND_MAXDEPTH
436 if (S_ISDIR(statbuf->st_mode))
437 if (depth == minmaxdepth[1])
438 return SKIP;
439#endif
440 /* Cannot return 0: our caller, recursive_action(), 447 /* Cannot return 0: our caller, recursive_action(),
441 * will perror() and skip dirs (if called on dir) */ 448 * will perror() and skip dirs (if called on dir) */
442 return (i & SKIP) ? SKIP : TRUE; 449 return (r & SKIP) ? SKIP : TRUE;
443#undef minmaxdepth 450#undef minmaxdepth
444} 451}
445 452
@@ -914,13 +921,14 @@ IF_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,)
914 struct stat stbuf; 921 struct stat stbuf;
915 if (!G.xdev_count) { 922 if (!G.xdev_count) {
916 G.xdev_count = firstopt - 1; 923 G.xdev_count = firstopt - 1;
917 G.xdev_dev = xmalloc(G.xdev_count * sizeof(dev_t)); 924 G.xdev_dev = xzalloc(G.xdev_count * sizeof(G.xdev_dev[0]));
918 for (i = 1; i < firstopt; i++) { 925 for (i = 1; i < firstopt; i++) {
919 /* not xstat(): shouldn't bomb out on 926 /* not xstat(): shouldn't bomb out on
920 * "find not_exist exist -xdev" */ 927 * "find not_exist exist -xdev" */
921 if (stat(argv[i], &stbuf)) 928 if (stat(argv[i], &stbuf) == 0)
922 stbuf.st_dev = -1L; 929 G.xdev_dev[i-1] = stbuf.st_dev;
923 G.xdev_dev[i-1] = stbuf.st_dev; 930 /* else G.xdev_dev[i-1] stays 0 and
931 * won't match any real device dev_t */
924 } 932 }
925 } 933 }
926 argp[0] = (char*)"-a"; 934 argp[0] = (char*)"-a";