diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-01-23 05:27:42 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-01-23 05:27:42 +0000 |
commit | 97d86f2bb59751be52fb3ee5cdb8b06e7b3bb98f (patch) | |
tree | 68724d2a1026005a4ab84f2dcf161b7fa09f4d97 | |
parent | be65c350ae535f80ea369be5366e09f730ab7ba8 (diff) | |
download | busybox-w32-97d86f2bb59751be52fb3ee5cdb8b06e7b3bb98f.tar.gz busybox-w32-97d86f2bb59751be52fb3ee5cdb8b06e7b3bb98f.tar.bz2 busybox-w32-97d86f2bb59751be52fb3ee5cdb8b06e7b3bb98f.zip |
Apply patch from Ghozlane Toumi to add -inum support to find.
Apply patch from Ghozlane Toumi to make find smaller by combining
similar error messages
Forward port find -newer support from busybox stable that was
missing from unstable. -Erik.
Fixup usage messages for find. -Erik
-rw-r--r-- | findutils/Config.in | 15 | ||||
-rw-r--r-- | findutils/find.c | 60 | ||||
-rw-r--r-- | include/usage.h | 16 |
3 files changed, 79 insertions, 12 deletions
diff --git a/findutils/Config.in b/findutils/Config.in index 42400ffb8..7cfcf2fa4 100644 --- a/findutils/Config.in +++ b/findutils/Config.in | |||
@@ -39,6 +39,21 @@ config CONFIG_FEATURE_FIND_XDEV | |||
39 | help | 39 | help |
40 | Please submit a patch to add help text for this item. | 40 | Please submit a patch to add help text for this item. |
41 | 41 | ||
42 | config CONFIG_FEATURE_FIND_NEWER | ||
43 | bool " Enable -newer option for comparing file mtimes" | ||
44 | default y | ||
45 | depends on CONFIG_FIND | ||
46 | help | ||
47 | Support the 'find -newer' option for finding any files which have | ||
48 | a modified time that is more recent than the specified FILE. | ||
49 | |||
50 | config CONFIG_FEATURE_FIND_INUM | ||
51 | bool " Enable inode number matching (-inum) option" | ||
52 | default y | ||
53 | depends on CONFIG_FIND | ||
54 | help | ||
55 | Support the 'fine -inum' option for searching by inode number. | ||
56 | |||
42 | config CONFIG_GREP | 57 | config CONFIG_GREP |
43 | bool "grep" | 58 | bool "grep" |
44 | default n | 59 | default n |
diff --git a/findutils/find.c b/findutils/find.c index b0f4bca6b..048aac503 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -34,6 +34,9 @@ | |||
34 | #include <ctype.h> | 34 | #include <ctype.h> |
35 | #include "busybox.h" | 35 | #include "busybox.h" |
36 | 36 | ||
37 | //XXX just found out about libbb/messages.c . maybe move stuff there ? - ghoz | ||
38 | const char msg_req_arg[] = "option `%s' requires an argument"; | ||
39 | const char msg_invalid_arg[] = "invalid argument `%s' to `%s'"; | ||
37 | 40 | ||
38 | static char *pattern; | 41 | static char *pattern; |
39 | 42 | ||
@@ -56,6 +59,13 @@ static dev_t *xdev_dev; | |||
56 | static int xdev_count = 0; | 59 | static int xdev_count = 0; |
57 | #endif | 60 | #endif |
58 | 61 | ||
62 | #ifdef CONFIG_FEATURE_FIND_NEWER | ||
63 | time_t newer_mtime; | ||
64 | #endif | ||
65 | |||
66 | #ifdef CONFIG_FEATURE_FIND_INUM | ||
67 | static ino_t inode_num; | ||
68 | #endif | ||
59 | 69 | ||
60 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | 70 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) |
61 | { | 71 | { |
@@ -109,7 +119,19 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | |||
109 | } | 119 | } |
110 | } | 120 | } |
111 | #endif | 121 | #endif |
112 | 122 | #ifdef CONFIG_FEATURE_FIND_NEWER | |
123 | if (newer_mtime != 0) { | ||
124 | time_t file_age = newer_mtime - statbuf->st_mtime; | ||
125 | if (file_age >= 0) | ||
126 | goto no_match; | ||
127 | } | ||
128 | #endif | ||
129 | #ifdef CONFIG_FEATURE_FIND_INUM | ||
130 | if (inode_num != 0) { | ||
131 | if (!(statbuf->st_ino == inode_num)) | ||
132 | goto no_match; | ||
133 | } | ||
134 | #endif | ||
113 | puts(fileName); | 135 | puts(fileName); |
114 | no_match: | 136 | no_match: |
115 | return (TRUE); | 137 | return (TRUE); |
@@ -145,7 +167,7 @@ static int find_type(char *type) | |||
145 | } | 167 | } |
146 | 168 | ||
147 | if (mask == 0 || type[1] != '\0') | 169 | if (mask == 0 || type[1] != '\0') |
148 | error_msg_and_die("invalid argument `%s' to `-type'", type); | 170 | error_msg_and_die(msg_invalid_arg, type, "-type"); |
149 | 171 | ||
150 | return mask; | 172 | return mask; |
151 | } | 173 | } |
@@ -170,24 +192,22 @@ int find_main(int argc, char **argv) | |||
170 | } | 192 | } |
171 | else if (strcmp(argv[i], "-name") == 0) { | 193 | else if (strcmp(argv[i], "-name") == 0) { |
172 | if (++i == argc) | 194 | if (++i == argc) |
173 | error_msg_and_die("option `-name' requires an argument"); | 195 | error_msg_and_die(msg_req_arg, "-name"); |
174 | pattern = argv[i]; | 196 | pattern = argv[i]; |
175 | #ifdef CONFIG_FEATURE_FIND_TYPE | 197 | #ifdef CONFIG_FEATURE_FIND_TYPE |
176 | } else if (strcmp(argv[i], "-type") == 0) { | 198 | } else if (strcmp(argv[i], "-type") == 0) { |
177 | if (++i == argc) | 199 | if (++i == argc) |
178 | error_msg_and_die("option `-type' requires an argument"); | 200 | error_msg_and_die(msg_req_arg, "-type"); |
179 | type_mask = find_type(argv[i]); | 201 | type_mask = find_type(argv[i]); |
180 | #endif | 202 | #endif |
181 | #ifdef CONFIG_FEATURE_FIND_PERM | 203 | #ifdef CONFIG_FEATURE_FIND_PERM |
182 | } else if (strcmp(argv[i], "-perm") == 0) { | 204 | } else if (strcmp(argv[i], "-perm") == 0) { |
183 | char *end; | 205 | char *end; |
184 | if (++i == argc) | 206 | if (++i == argc) |
185 | error_msg_and_die("option `-perm' requires an argument"); | 207 | error_msg_and_die(msg_req_arg, "-perm"); |
186 | perm_mask = strtol(argv[i], &end, 8); | 208 | perm_mask = strtol(argv[i], &end, 8); |
187 | if (end[0] != '\0') | 209 | if ((end[0] != '\0') || (perm_mask > 07777)) |
188 | error_msg_and_die("invalid argument `%s' to `-perm'", argv[i]); | 210 | error_msg_and_die(msg_invalid_arg, argv[i], "-perm"); |
189 | if (perm_mask > 07777) | ||
190 | error_msg_and_die("invalid argument `%s' to `-perm'", argv[i]); | ||
191 | if ((perm_char = argv[i][0]) == '-') | 211 | if ((perm_char = argv[i][0]) == '-') |
192 | perm_mask = -perm_mask; | 212 | perm_mask = -perm_mask; |
193 | #endif | 213 | #endif |
@@ -195,10 +215,10 @@ int find_main(int argc, char **argv) | |||
195 | } else if (strcmp(argv[i], "-mtime") == 0) { | 215 | } else if (strcmp(argv[i], "-mtime") == 0) { |
196 | char *end; | 216 | char *end; |
197 | if (++i == argc) | 217 | if (++i == argc) |
198 | error_msg_and_die("option `-mtime' requires an argument"); | 218 | error_msg_and_die(msg_req_arg, "-mtime"); |
199 | mtime_days = strtol(argv[i], &end, 10); | 219 | mtime_days = strtol(argv[i], &end, 10); |
200 | if (end[0] != '\0') | 220 | if (end[0] != '\0') |
201 | error_msg_and_die("invalid argument `%s' to `-mtime'", argv[i]); | 221 | error_msg_and_die(msg_invalid_arg, argv[i], "-mtime"); |
202 | if ((mtime_char = argv[i][0]) == '-') | 222 | if ((mtime_char = argv[i][0]) == '-') |
203 | mtime_days = -mtime_days; | 223 | mtime_days = -mtime_days; |
204 | #endif | 224 | #endif |
@@ -223,6 +243,24 @@ int find_main(int argc, char **argv) | |||
223 | } | 243 | } |
224 | } | 244 | } |
225 | #endif | 245 | #endif |
246 | #ifdef CONFIG_FEATURE_FIND_NEWER | ||
247 | } else if (strcmp(argv[i], "-newer") == 0) { | ||
248 | struct stat stat_newer; | ||
249 | if (++i == argc) | ||
250 | error_msg_and_die(msg_req_arg, "-newer"); | ||
251 | if (stat (argv[i], &stat_newer) != 0) | ||
252 | error_msg_and_die("file %s not found", argv[i]); | ||
253 | newer_mtime = stat_newer.st_mtime; | ||
254 | #endif | ||
255 | #ifdef CONFIG_FEATURE_FIND_INUM | ||
256 | } else if (strcmp(argv[i], "-inum") == 0) { | ||
257 | char *end; | ||
258 | if (++i == argc) | ||
259 | error_msg_and_die(msg_req_arg, "-inum"); | ||
260 | inode_num = strtol(argv[i], &end, 10); | ||
261 | if (end[0] != '\0') | ||
262 | error_msg_and_die(msg_invalid_arg, argv[i], "-inum"); | ||
263 | #endif | ||
226 | } else | 264 | } else |
227 | show_usage(); | 265 | show_usage(); |
228 | } | 266 | } |
diff --git a/include/usage.h b/include/usage.h index beb32fdc9..077306bdf 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -568,6 +568,16 @@ | |||
568 | #else | 568 | #else |
569 | #define USAGE_FIND_MTIME(a) | 569 | #define USAGE_FIND_MTIME(a) |
570 | #endif | 570 | #endif |
571 | #ifdef CONFIG_FEATURE_FIND_NEWER | ||
572 | #define USAGE_FIND_NEWER(a) a | ||
573 | #else | ||
574 | #define USAGE_FIND_NEWER(a) | ||
575 | #endif | ||
576 | #ifdef CONFIG_FEATURE_FIND_INUM | ||
577 | #define USAGE_FIND_INUM(a) a | ||
578 | #else | ||
579 | #define USAGE_FIND_INUM(a) | ||
580 | #endif | ||
571 | 581 | ||
572 | #define find_trivial_usage \ | 582 | #define find_trivial_usage \ |
573 | "[PATH...] [EXPRESSION]" | 583 | "[PATH...] [EXPRESSION]" |
@@ -583,7 +593,11 @@ | |||
583 | ) USAGE_FIND_PERM( \ | 593 | ) USAGE_FIND_PERM( \ |
584 | "\n\t-perm PERMS\tPermissions match any of (+NNN); all of (-NNN);\n\t\t\tor exactly (NNN)" \ | 594 | "\n\t-perm PERMS\tPermissions match any of (+NNN); all of (-NNN);\n\t\t\tor exactly (NNN)" \ |
585 | ) USAGE_FIND_MTIME( \ | 595 | ) USAGE_FIND_MTIME( \ |
586 | "\n\t-mtime TIME\tModified time is greater than (+N); less than (-N);\n\t\t\tor exactly (N) days") | 596 | "\n\t-mtime TIME\tModified time is greater than (+N); less than (-N);\n\t\t\tor exactly (N) days" \ |
597 | ) USAGE_FIND_NEWER( \ | ||
598 | "\n\t-newer FILE\tModified time is more recent than FILE's" \ | ||
599 | ) USAGE_FIND_INUM( \ | ||
600 | "\n\t-inum N\t\tFile has inode number N") | ||
587 | #define find_example_usage \ | 601 | #define find_example_usage \ |
588 | "$ find / -name /etc/passwd\n" \ | 602 | "$ find / -name /etc/passwd\n" \ |
589 | "/etc/passwd\n" | 603 | "/etc/passwd\n" |