diff options
author | Paul Fox <pgf@brightstareng.com> | 2006-01-13 21:05:41 +0000 |
---|---|---|
committer | Paul Fox <pgf@brightstareng.com> | 2006-01-13 21:05:41 +0000 |
commit | 72d1a2357d2168f241458e4d6cebb7589ac82f4f (patch) | |
tree | f3152b7eb88a52763740683d918e61aacbb9ade9 | |
parent | 4a1865ca5eaf6bebc76ef8066c19e95df0edc7c3 (diff) | |
download | busybox-w32-72d1a2357d2168f241458e4d6cebb7589ac82f4f.tar.gz busybox-w32-72d1a2357d2168f241458e4d6cebb7589ac82f4f.tar.bz2 busybox-w32-72d1a2357d2168f241458e4d6cebb7589ac82f4f.zip |
add find's "-mmin" option. configurable.
-rw-r--r-- | findutils/Config.in | 10 | ||||
-rw-r--r-- | findutils/find.c | 27 | ||||
-rw-r--r-- | include/usage.h | 9 |
3 files changed, 44 insertions, 2 deletions
diff --git a/findutils/Config.in b/findutils/Config.in index 3c28ec03a..050fe901d 100644 --- a/findutils/Config.in +++ b/findutils/Config.in | |||
@@ -17,7 +17,15 @@ config CONFIG_FEATURE_FIND_MTIME | |||
17 | depends on CONFIG_FIND | 17 | depends on CONFIG_FIND |
18 | help | 18 | help |
19 | Allow searching based on the modification time of | 19 | Allow searching based on the modification time of |
20 | files. | 20 | files, in days. |
21 | |||
22 | config CONFIG_FEATURE_FIND_MMIN | ||
23 | bool " Enable modified time matching (-min) option" | ||
24 | default y | ||
25 | depends on CONFIG_FIND | ||
26 | help | ||
27 | Allow searching based on the modification time of | ||
28 | files, in minutes. | ||
21 | 29 | ||
22 | config CONFIG_FEATURE_FIND_PERM | 30 | config CONFIG_FEATURE_FIND_PERM |
23 | bool " Enable permissions matching (-perm) option" | 31 | bool " Enable permissions matching (-perm) option" |
diff --git a/findutils/find.c b/findutils/find.c index 75ed4e208..603c20643 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -53,6 +53,11 @@ static char mtime_char; | |||
53 | static int mtime_days; | 53 | static int mtime_days; |
54 | #endif | 54 | #endif |
55 | 55 | ||
56 | #ifdef CONFIG_FEATURE_FIND_MMIN | ||
57 | static char mmin_char; | ||
58 | static int mmin_mins; | ||
59 | #endif | ||
60 | |||
56 | #ifdef CONFIG_FEATURE_FIND_XDEV | 61 | #ifdef CONFIG_FEATURE_FIND_XDEV |
57 | static dev_t *xdev_dev; | 62 | static dev_t *xdev_dev; |
58 | static int xdev_count = 0; | 63 | static int xdev_count = 0; |
@@ -109,6 +114,17 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | |||
109 | goto no_match; | 114 | goto no_match; |
110 | } | 115 | } |
111 | #endif | 116 | #endif |
117 | #ifdef CONFIG_FEATURE_FIND_MMIN | ||
118 | if (mmin_char != 0) { | ||
119 | time_t file_age = time(NULL) - statbuf->st_mtime; | ||
120 | time_t mmin_secs = mmin_mins * 60; | ||
121 | if (!((isdigit(mmin_char) && file_age >= mmin_secs && | ||
122 | file_age < mmin_secs + 60) || | ||
123 | (mmin_char == '+' && file_age >= mmin_secs + 60) || | ||
124 | (mmin_char == '-' && file_age < mmin_secs))) | ||
125 | goto no_match; | ||
126 | } | ||
127 | #endif | ||
112 | #ifdef CONFIG_FEATURE_FIND_XDEV | 128 | #ifdef CONFIG_FEATURE_FIND_XDEV |
113 | if (xdev_count) { | 129 | if (xdev_count) { |
114 | int i; | 130 | int i; |
@@ -239,6 +255,17 @@ int find_main(int argc, char **argv) | |||
239 | if ((mtime_char = argv[i][0]) == '-') | 255 | if ((mtime_char = argv[i][0]) == '-') |
240 | mtime_days = -mtime_days; | 256 | mtime_days = -mtime_days; |
241 | #endif | 257 | #endif |
258 | #ifdef CONFIG_FEATURE_FIND_MMIN | ||
259 | } else if (strcmp(argv[i], "-mmin") == 0) { | ||
260 | char *end; | ||
261 | if (++i == argc) | ||
262 | bb_error_msg_and_die(msg_req_arg, "-mmin"); | ||
263 | mmin_mins = strtol(argv[i], &end, 10); | ||
264 | if (end[0] != '\0') | ||
265 | bb_error_msg_and_die(msg_invalid_arg, argv[i], "-mmin"); | ||
266 | if ((mmin_char = argv[i][0]) == '-') | ||
267 | mmin_mins = -mmin_mins; | ||
268 | #endif | ||
242 | #ifdef CONFIG_FEATURE_FIND_XDEV | 269 | #ifdef CONFIG_FEATURE_FIND_XDEV |
243 | } else if (strcmp(argv[i], "-xdev") == 0) { | 270 | } else if (strcmp(argv[i], "-xdev") == 0) { |
244 | struct stat stbuf; | 271 | struct stat stbuf; |
diff --git a/include/usage.h b/include/usage.h index 9387238ab..81f0e1d6d 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -722,6 +722,11 @@ | |||
722 | #else | 722 | #else |
723 | # define USAGE_FIND_MTIME(a) | 723 | # define USAGE_FIND_MTIME(a) |
724 | #endif | 724 | #endif |
725 | #ifdef CONFIG_FEATURE_FIND_MMIN | ||
726 | #define USAGE_FIND_MMIN(a) a | ||
727 | #else | ||
728 | #define USAGE_FIND_MMIN(a) | ||
729 | #endif | ||
725 | #ifdef CONFIG_FEATURE_FIND_NEWER | 730 | #ifdef CONFIG_FEATURE_FIND_NEWER |
726 | # define USAGE_FIND_NEWER(a) a | 731 | # define USAGE_FIND_NEWER(a) a |
727 | #else | 732 | #else |
@@ -752,7 +757,9 @@ | |||
752 | ) USAGE_FIND_PERM( \ | 757 | ) USAGE_FIND_PERM( \ |
753 | "\n\t-perm PERMS\tPermissions match any of (+NNN); all of (-NNN);\n\t\t\tor exactly (NNN)" \ | 758 | "\n\t-perm PERMS\tPermissions match any of (+NNN); all of (-NNN);\n\t\t\tor exactly (NNN)" \ |
754 | ) USAGE_FIND_MTIME( \ | 759 | ) USAGE_FIND_MTIME( \ |
755 | "\n\t-mtime TIME\tModified time is greater than (+N); less than (-N);\n\t\t\tor exactly (N) days" \ | 760 | "\n\t-mtime DAYS\tModified time is greater than (+N); less than (-N);\n\t\t\tor exactly (N) days" \ |
761 | ) USAGE_FIND_MMIN( \ | ||
762 | "\n\t-mmin MINS\tModified time is greater than (+N); less than (-N);\n\t\t\tor exactly (N) minutes" \ | ||
756 | ) USAGE_FIND_NEWER( \ | 763 | ) USAGE_FIND_NEWER( \ |
757 | "\n\t-newer FILE\tModified time is more recent than FILE's" \ | 764 | "\n\t-newer FILE\tModified time is more recent than FILE's" \ |
758 | ) USAGE_FIND_INUM( \ | 765 | ) USAGE_FIND_INUM( \ |