[BusyBox] [PATCH] busybox find -mtime fixes

Ian Abbott abbotti at farscape.privy.mev.co.uk
Wed Dec 11 05:50:06 UTC 2002


The find -mtime option doesn't behave very much like the GNU version.  The main
problem is that the +days and -days are reversed.

This patch makes it behave more like the GNU version as follows:

* -mtime +{days} now finds files > {days} days old (this is the reverse of
  current behavior, and is also now strictly greater, not >=);
* -mtime -{days} now finds files < {days} days old (this is the reverse of
  current behavior);
* -mtime {days} now finds files >= {days} days old, but < {days}+1 days old (the
  times matched have been shifted back by 24 hours compared to current behavior);
* -mtime 0, -mtime +0 and -mtime -0 may now be used.

Note that this patch will break scripts depending on the old behavior, but will
fix those scripts expecting the normal behavior!

Index: findutils/find.c
===================================================================
RCS file: /var/cvs/busybox/findutils/find.c,v
retrieving revision 1.35
diff -u -r1.35 find.c
--- findutils/find.c	24 Jul 2002 00:34:48 -0000	1.35
+++ findutils/find.c	11 Dec 2002 12:20:06 -0000
@@ -84,13 +84,13 @@
 	}
 #endif
 #ifdef CONFIG_FEATURE_FIND_MTIME
-	if (mtime_days != 0) {
+	if (mtime_char != 0) {
 		time_t file_age = time(NULL) - statbuf->st_mtime;
 		time_t mtime_secs = mtime_days * 24 * 60 * 60;
-		if (!((isdigit(mtime_char) && mtime_secs >= file_age &&
-						mtime_secs < file_age + 24 * 60 * 60) ||
-				(mtime_char == '+' && mtime_secs >= file_age) || 
-				(mtime_char == '-' && mtime_secs < file_age)))
+		if (!((isdigit(mtime_char) && file_age >= mtime_secs &&
+						file_age < mtime_secs + 24 * 60 * 60) ||
+				(mtime_char == '+' && file_age > mtime_secs) || 
+				(mtime_char == '-' && file_age < mtime_secs)))
 			goto no_match;
 	}
 #endif





More information about the busybox mailing list