diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-26 23:00:05 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-01-26 23:00:05 +0000 |
commit | fc7f92253ae1c4f050e5ea2322b53b0e81bf96be (patch) | |
tree | dc1023059186ea2b817a4b7859328b5f3625c9c6 /findutils/find.c | |
parent | 8b942c66395436c6dce3a280d8fa227c0453b9bc (diff) | |
download | busybox-w32-fc7f92253ae1c4f050e5ea2322b53b0e81bf96be.tar.gz busybox-w32-fc7f92253ae1c4f050e5ea2322b53b0e81bf96be.tar.bz2 busybox-w32-fc7f92253ae1c4f050e5ea2322b53b0e81bf96be.zip |
find: fix -mtime, -mmin, -perm (+ add symbolic perm handling)
chmod: better name for a variable
Diffstat (limited to 'findutils/find.c')
-rw-r--r-- | findutils/find.c | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/findutils/find.c b/findutils/find.c index f2e3c6d07..f7d95325a 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -45,8 +45,8 @@ | |||
45 | * (no output) | 45 | * (no output) |
46 | */ | 46 | */ |
47 | 47 | ||
48 | #include "busybox.h" | ||
49 | #include <fnmatch.h> | 48 | #include <fnmatch.h> |
49 | #include "busybox.h" | ||
50 | 50 | ||
51 | USE_FEATURE_FIND_XDEV(static dev_t *xdev_dev;) | 51 | USE_FEATURE_FIND_XDEV(static dev_t *xdev_dev;) |
52 | USE_FEATURE_FIND_XDEV(static int xdev_count;) | 52 | USE_FEATURE_FIND_XDEV(static int xdev_count;) |
@@ -62,9 +62,9 @@ typedef struct { | |||
62 | ACTS(name, char *pattern;) | 62 | ACTS(name, char *pattern;) |
63 | USE_FEATURE_FIND_PRINT0(ACTS(print0)) | 63 | USE_FEATURE_FIND_PRINT0(ACTS(print0)) |
64 | USE_FEATURE_FIND_TYPE( ACTS(type, int type_mask;)) | 64 | USE_FEATURE_FIND_TYPE( ACTS(type, int type_mask;)) |
65 | USE_FEATURE_FIND_PERM( ACTS(perm, char perm_char; int perm_mask;)) | 65 | USE_FEATURE_FIND_PERM( ACTS(perm, char perm_char; mode_t perm_mask;)) |
66 | USE_FEATURE_FIND_MTIME( ACTS(mtime, char mtime_char; int mtime_days;)) | 66 | USE_FEATURE_FIND_MTIME( ACTS(mtime, char mtime_char; unsigned mtime_days;)) |
67 | USE_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; int mmin_mins;)) | 67 | USE_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; unsigned mmin_mins;)) |
68 | USE_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;)) | 68 | USE_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;)) |
69 | USE_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;)) | 69 | USE_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;)) |
70 | USE_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; int *subst_count; int exec_argc;)) | 70 | USE_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; int *subst_count; int exec_argc;)) |
@@ -147,20 +147,27 @@ ACTF(type) | |||
147 | #if ENABLE_FEATURE_FIND_PERM | 147 | #if ENABLE_FEATURE_FIND_PERM |
148 | ACTF(perm) | 148 | ACTF(perm) |
149 | { | 149 | { |
150 | return !((isdigit(ap->perm_char) && (statbuf->st_mode & 07777) == ap->perm_mask) | 150 | /* -perm +mode: at least one of perm_mask bits are set */ |
151 | || (ap->perm_char == '-' && (statbuf->st_mode & ap->perm_mask) == ap->perm_mask) | 151 | if (ap->perm_char == '+') |
152 | || (ap->perm_char == '+' && (statbuf->st_mode & ap->perm_mask) != 0)); | 152 | return (statbuf->st_mode & ap->perm_mask) != 0; |
153 | /* -perm -mode: all of perm_mask are set */ | ||
154 | if (ap->perm_char == '-') | ||
155 | return (statbuf->st_mode & ap->perm_mask) == ap->perm_mask; | ||
156 | /* -perm mode: file mode must match perm_mask */ | ||
157 | return (statbuf->st_mode & 07777) == ap->perm_mask; | ||
153 | } | 158 | } |
154 | #endif | 159 | #endif |
155 | #if ENABLE_FEATURE_FIND_MTIME | 160 | #if ENABLE_FEATURE_FIND_MTIME |
156 | ACTF(mtime) | 161 | ACTF(mtime) |
157 | { | 162 | { |
158 | time_t file_age = time(NULL) - statbuf->st_mtime; | 163 | time_t file_age = time(NULL) - statbuf->st_mtime; |
159 | time_t mtime_secs = ap->mtime_days * 24 * 60 * 60; | 164 | time_t mtime_secs = ap->mtime_days * 24*60*60; |
160 | return !((isdigit(ap->mtime_char) && file_age >= mtime_secs | 165 | if (ap->mtime_char == '+') |
161 | && file_age < mtime_secs + 24 * 60 * 60) | 166 | return file_age >= mtime_secs + 24*60*60; |
162 | || (ap->mtime_char == '+' && file_age >= mtime_secs + 24 * 60 * 60) | 167 | if (ap->mtime_char == '-') |
163 | || (ap->mtime_char == '-' && file_age < mtime_secs)); | 168 | return file_age < mtime_secs; |
169 | /* just numeric mtime */ | ||
170 | return file_age >= mtime_secs && file_age < (mtime_secs + 24*60*60); | ||
164 | } | 171 | } |
165 | #endif | 172 | #endif |
166 | #if ENABLE_FEATURE_FIND_MMIN | 173 | #if ENABLE_FEATURE_FIND_MMIN |
@@ -168,22 +175,24 @@ ACTF(mmin) | |||
168 | { | 175 | { |
169 | time_t file_age = time(NULL) - statbuf->st_mtime; | 176 | time_t file_age = time(NULL) - statbuf->st_mtime; |
170 | time_t mmin_secs = ap->mmin_mins * 60; | 177 | time_t mmin_secs = ap->mmin_mins * 60; |
171 | return !((isdigit(ap->mmin_char) && file_age >= mmin_secs | 178 | if (ap->mmin_char == '+') |
172 | && file_age < mmin_secs + 60) | 179 | return file_age >= mmin_secs + 60; |
173 | || (ap->mmin_char == '+' && file_age >= mmin_secs + 60) | 180 | if (ap->mmin_char == '-') |
174 | || (ap->mmin_char == '-' && file_age < mmin_secs)); | 181 | return file_age < mmin_secs; |
182 | /* just numeric mmin */ | ||
183 | return file_age >= mmin_secs && file_age < (mmin_secs + 60); | ||
175 | } | 184 | } |
176 | #endif | 185 | #endif |
177 | #if ENABLE_FEATURE_FIND_NEWER | 186 | #if ENABLE_FEATURE_FIND_NEWER |
178 | ACTF(newer) | 187 | ACTF(newer) |
179 | { | 188 | { |
180 | return (ap->newer_mtime >= statbuf->st_mtime); | 189 | return (ap->newer_mtime < statbuf->st_mtime); |
181 | } | 190 | } |
182 | #endif | 191 | #endif |
183 | #if ENABLE_FEATURE_FIND_INUM | 192 | #if ENABLE_FEATURE_FIND_INUM |
184 | ACTF(inum) | 193 | ACTF(inum) |
185 | { | 194 | { |
186 | return (statbuf->st_ino != ap->inode_num); | 195 | return (statbuf->st_ino == ap->inode_num); |
187 | } | 196 | } |
188 | #endif | 197 | #endif |
189 | #if ENABLE_FEATURE_FIND_EXEC | 198 | #if ENABLE_FEATURE_FIND_EXEC |
@@ -299,6 +308,13 @@ static int find_type(char *type) | |||
299 | } | 308 | } |
300 | #endif | 309 | #endif |
301 | 310 | ||
311 | static const char* plus_minus_num(const char* str) | ||
312 | { | ||
313 | if (*str == '-' || *str == '+') | ||
314 | str++; | ||
315 | return str; | ||
316 | } | ||
317 | |||
302 | static action*** parse_params(char **argv) | 318 | static action*** parse_params(char **argv) |
303 | { | 319 | { |
304 | action*** appp; | 320 | action*** appp; |
@@ -391,10 +407,11 @@ static action*** parse_params(char **argv) | |||
391 | if (!*++argv) | 407 | if (!*++argv) |
392 | bb_error_msg_and_die(bb_msg_requires_arg, arg); | 408 | bb_error_msg_and_die(bb_msg_requires_arg, arg); |
393 | ap = ALLOC_ACTION(perm); | 409 | ap = ALLOC_ACTION(perm); |
394 | ap->perm_mask = xstrtol_range(arg1, 8, 0, 07777); | ||
395 | ap->perm_char = arg1[0]; | 410 | ap->perm_char = arg1[0]; |
396 | if (ap->perm_char == '-') | 411 | arg1 = plus_minus_num(arg1); |
397 | ap->perm_mask = -ap->perm_mask; | 412 | ap->perm_mask = 0; |
413 | if (!bb_parse_mode(arg1, &ap->perm_mask)) | ||
414 | bb_error_msg_and_die("invalid mode: %s", arg1); | ||
398 | } | 415 | } |
399 | #endif | 416 | #endif |
400 | #if ENABLE_FEATURE_FIND_MTIME | 417 | #if ENABLE_FEATURE_FIND_MTIME |
@@ -403,10 +420,8 @@ static action*** parse_params(char **argv) | |||
403 | if (!*++argv) | 420 | if (!*++argv) |
404 | bb_error_msg_and_die(bb_msg_requires_arg, arg); | 421 | bb_error_msg_and_die(bb_msg_requires_arg, arg); |
405 | ap = ALLOC_ACTION(mtime); | 422 | ap = ALLOC_ACTION(mtime); |
406 | ap->mtime_days = xatol(arg1); | ||
407 | ap->mtime_char = arg1[0]; | 423 | ap->mtime_char = arg1[0]; |
408 | if (ap->mtime_char == '-') | 424 | ap->mtime_days = xatoul(plus_minus_num(arg1)); |
409 | ap->mtime_days = -ap->mtime_days; | ||
410 | } | 425 | } |
411 | #endif | 426 | #endif |
412 | #if ENABLE_FEATURE_FIND_MMIN | 427 | #if ENABLE_FEATURE_FIND_MMIN |
@@ -415,10 +430,8 @@ static action*** parse_params(char **argv) | |||
415 | if (!*++argv) | 430 | if (!*++argv) |
416 | bb_error_msg_and_die(bb_msg_requires_arg, arg); | 431 | bb_error_msg_and_die(bb_msg_requires_arg, arg); |
417 | ap = ALLOC_ACTION(mmin); | 432 | ap = ALLOC_ACTION(mmin); |
418 | ap->mmin_mins = xatol(arg1); | ||
419 | ap->mmin_char = arg1[0]; | 433 | ap->mmin_char = arg1[0]; |
420 | if (ap->mmin_char == '-') | 434 | ap->mmin_mins = xatoul(plus_minus_num(arg1)); |
421 | ap->mmin_mins = -ap->mmin_mins; | ||
422 | } | 435 | } |
423 | #endif | 436 | #endif |
424 | #if ENABLE_FEATURE_FIND_NEWER | 437 | #if ENABLE_FEATURE_FIND_NEWER |