diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-08 11:10:43 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-08 11:10:43 +0000 |
commit | b04b4357ff5a5b5194a7ff3c875d8746fac9ff33 (patch) | |
tree | 59665356fb143c9b9f3bc089a33641d33beb6a57 | |
parent | bbd695d8010ab453a5a89ba6d7ebfe1a96b87b7d (diff) | |
download | busybox-w32-b04b4357ff5a5b5194a7ff3c875d8746fac9ff33.tar.gz busybox-w32-b04b4357ff5a5b5194a7ff3c875d8746fac9ff33.tar.bz2 busybox-w32-b04b4357ff5a5b5194a7ff3c875d8746fac9ff33.zip |
find: fix -prune more. Add big comment about it.
-rw-r--r-- | findutils/find.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/findutils/find.c b/findutils/find.c index 3eea53db0..594eafca4 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -120,20 +120,34 @@ static int exec_actions(action ***appp, const char *fileName, struct stat *statb | |||
120 | { | 120 | { |
121 | int cur_group; | 121 | int cur_group; |
122 | int cur_action; | 122 | int cur_action; |
123 | int rc = TRUE; | 123 | int rc = 0; |
124 | action **app, *ap; | 124 | action **app, *ap; |
125 | 125 | ||
126 | /* "action group" is a set of actions ANDed together. | ||
127 | * groups are ORed together. | ||
128 | * We simply evaluate each group until we find one in which all actions | ||
129 | * succeed. */ | ||
130 | |||
131 | /* -prune is special: if it is encountered, then we won't | ||
132 | * descend into current directory. It doesn't matter whether | ||
133 | * action group (in which -prune sits) will succeed or not: | ||
134 | * find * -prune -name 'f*' -o -name 'm*' -- prunes every dir | ||
135 | * find * -name 'f*' -o -prune -name 'm*' -- prunes all dirs | ||
136 | * not starting with 'f' */ | ||
137 | |||
138 | /* We invert TRUE bit (bit 0). Now 1 there means 'failure'. | ||
139 | * and bitwise OR in "rc |= TRUE ^ ap->f()" will: | ||
140 | * (1) make SKIP (-prune) bit stick; and (2) detect 'failure'. | ||
141 | * On return, bit is restored. */ | ||
142 | |||
126 | cur_group = -1; | 143 | cur_group = -1; |
127 | while ((app = appp[++cur_group])) { | 144 | while ((app = appp[++cur_group])) { |
128 | /* We invert TRUE bit (bit 0). Now 1 there means 'failure'. | 145 | rc &= ~TRUE; /* 'success' so far, clear TRUE bit */ |
129 | * and bitwise OR in "rc |= TRUE ^ ap->f()" will: | ||
130 | * (1) make SKIP bit stick; and (2) detect 'failure' */ | ||
131 | rc = 0; /* 'success' so far */ | ||
132 | cur_action = -1; | 146 | cur_action = -1; |
133 | while (1) { | 147 | while (1) { |
134 | ap = app[++cur_action]; | 148 | ap = app[++cur_action]; |
135 | if (!ap) /* all actions in group were successful */ | 149 | if (!ap) /* all actions in group were successful */ |
136 | return rc ^ TRUE; | 150 | return rc ^ TRUE; /* restore TRUE bit */ |
137 | rc |= TRUE ^ ap->f(fileName, statbuf, ap); | 151 | rc |= TRUE ^ ap->f(fileName, statbuf, ap); |
138 | #if ENABLE_FEATURE_FIND_NOT | 152 | #if ENABLE_FEATURE_FIND_NOT |
139 | if (ap->invert) rc ^= TRUE; | 153 | if (ap->invert) rc ^= TRUE; |
@@ -142,7 +156,7 @@ static int exec_actions(action ***appp, const char *fileName, struct stat *statb | |||
142 | break; | 156 | break; |
143 | } | 157 | } |
144 | } | 158 | } |
145 | return rc ^ TRUE; /* straighten things out */ | 159 | return rc ^ TRUE; /* restore TRUE bit */ |
146 | } | 160 | } |
147 | 161 | ||
148 | 162 | ||