[BusyBox] [PATCH] busybox find -mtime fixes

Ian Abbott abbotti at farscape.privy.mev.co.uk
Wed Dec 11 10:39:03 UTC 2002


On Wed, 11 Dec 2002 17:14:15 +0000, Ian Abbott <abbotti at farscape.privy.mev.co.uk> wrote:

>On Wed, 11 Dec 2002 12:53:10 +0000, I wrote:
>
>>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:
>
>Actually, my patch is not quite right yet - there is still a slight
>difference from GNU and POSIX.1 in the behaviour of -mtime +{days}. I'll
>do a replacement patch with this fixed, so don't apply it yet.

Here is the new version of the patch. I beleive this one makes the
-mtime option almost comply with POSIX.1. (To comply completely it
should compare the file time to the program initialisation time, not the
current time, which may vary as the program runs. This patch does not
address that minor issue.)

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 17:23:25 -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 + 24 * 60 * 60) || 
+				(mtime_char == '-' && file_age < mtime_secs)))
 			goto no_match;
 	}
 #endif




More information about the busybox mailing list