[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [BusyBox] find -newer patch
From: Geoffrey Espin <espin () idiom ! com>
Date: 2001-12-27 13:33:32
[Download RAW message or body]
Here's a patch that can be applied to busybox-0.60.2 and the
latest from CVS, 0.60.3-pre, that adds the "-newer <file>" ability
to 'find'.
Geoff
--
Geoffrey Espin / espin@idiom.com
--
["bb_find.patch" (text/plain)]
diff -b -Nu ../orig/Config.h ./Config.h
--- ../orig/Config.h Thu Dec 27 11:44:10 2001
+++ ./Config.h Thu Dec 27 12:21:21 2001
@@ -179,7 +179,7 @@
//#define BB_FEATURE_USE_DEVPS_PATCH
//
// show verbose usage messages
-//#define BB_FEATURE_VERBOSE_USAGE
+#define BB_FEATURE_VERBOSE_USAGE
//
// Use termios to manipulate the screen ('more' is prettier with this on)
//#define BB_FEATURE_USE_TERMIOS
@@ -360,8 +360,11 @@
// Support for the find -perm option.
#define BB_FEATURE_FIND_PERM
//
-// Support for the find -mtine option.
+// Support for the find -mtime option.
#define BB_FEATURE_FIND_MTIME
+//
+//// Support for the find -newer option.
+#define BB_FEATURE_FIND_NEWER
//
// Support for the -A -B and -C context flags in grep
//#define BB_FEATURE_GREP_CONTEXT
diff -b -Nu ../orig/find.c ./find.c
--- ../orig/find.c Thu Dec 27 11:44:10 2001
+++ ./find.c Thu Dec 27 11:44:10 2001
@@ -51,6 +51,10 @@
static int mtime_days;
#endif
+#ifdef BB_FEATURE_FIND_NEWER
+time_t newer_mtime;
+#endif
+
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{
if (pattern != NULL) {
@@ -88,6 +92,13 @@
goto no_match;
}
#endif
+#ifdef BB_FEATURE_FIND_NEWER
+ if (newer_mtime != 0) {
+ time_t file_age = newer_mtime - statbuf->st_mtime;
+ if (file_age >= 0)
+ goto no_match;
+ }
+#endif
puts(fileName);
no_match:
return (TRUE);
@@ -179,6 +190,15 @@
error_msg_and_die("invalid argument `%s' to `-mtime'", argv[i]);
if ((mtime_char = argv[i][0]) == '-')
mtime_days = -mtime_days;
+#endif
+#ifdef BB_FEATURE_FIND_NEWER
+ } else if (strcmp(argv[i], "-newer") == 0) {
+ struct stat stat_newer;
+ if (++i == argc)
+ error_msg_and_die("option `-newer' requires an argument");
+ if (stat (argv[i], &stat_newer) != 0)
+ error_msg_and_die("file %s not found", argv[i]);
+ newer_mtime = stat_newer.st_mtime;
#endif
} else
show_usage();
diff -b -Nu ../orig/usage.h ./usage.h
--- ../orig/usage.h Fri Oct 26 16:08:05 2001
+++ ./usage.h Thu Dec 27 12:15:12 2001
@@ -448,6 +448,11 @@
#else
#define USAGE_FIND_MTIME(a)
#endif
+#ifdef BB_FEATURE_FIND_NEWER
+ #define USAGE_FIND_NEWER(a) a
+#else
+ #define USAGE_FIND_NEWER(a)
+#endif
#define find_trivial_usage \
"[PATH...] [EXPRESSION]"
@@ -463,7 +468,9 @@
) USAGE_FIND_PERM( \
"\n\t-perm PERMS\tPermissions match any of (+NNN); all of (-NNN);\n\t\t\tor exactly (NNN)" \
) USAGE_FIND_MTIME( \
- "\n\t-mtime TIME\tModified time is greater than (+N); less than (-N);\n\t\t\tor exactly (N) days")
+ "\n\t-mtime TIME\tModified time is greater than (+N); less than (-N);\n\t\t\tor exactly (N) days"\
+) USAGE_FIND_NEWER( \
+ "\n\t-newer FILE\tModified time is more recent than FILE's")
#define find_example_usage \
"$ find / -name /etc/passwd\n" \
"/etc/passwd\n"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic