svn commit: r248446 - head/usr.bin/find

Jilles Tjoelker jilles at FreeBSD.org
Sun Mar 17 22:51:59 UTC 2013


Author: jilles
Date: Sun Mar 17 22:51:58 2013
New Revision: 248446
URL: http://svnweb.freebsd.org/changeset/base/248446

Log:
  find: Include nanoseconds when comparing timestamps of files.
  
  When comparing to the timestamp of a given file using -newer, -Xnewer and
  -newerXY (where X and Y are one of m, c, a, B), include nanoseconds in the
  comparison.
  
  The primaries that compare a timestamp of a file to a given value (-Xmin,
  -Xtime, -newerXt) continue to compare times in whole seconds.
  
  Note that the default value 0 of vfs.timestamp_precision almost always
  causes the nanoseconds part to be 0. However, touch -d can set a timestamp
  to the microsecond regardless of that sysctl.
  
  MFC after:	1 week

Modified:
  head/usr.bin/find/find.h
  head/usr.bin/find/function.c

Modified: head/usr.bin/find/find.h
==============================================================================
--- head/usr.bin/find/find.h	Sun Mar 17 22:24:08 2013	(r248445)
+++ head/usr.bin/find/find.h	Sun Mar 17 22:51:58 2013	(r248446)
@@ -88,7 +88,7 @@ typedef struct _plandata {
 		nlink_t _l_data;		/* link count */
 		short _d_data;			/* level depth (-1 to N) */
 		off_t _o_data;			/* file size */
-		time_t _t_data;			/* time value */
+		struct timespec _t_data;	/* time value */
 		uid_t _u_data;			/* uid */
 		short _mt_data;			/* mount flags */
 		struct _plandata *_p_data[2];	/* PLAN trees */

Modified: head/usr.bin/find/function.c
==============================================================================
--- head/usr.bin/find/function.c	Sun Mar 17 22:24:08 2013	(r248445)
+++ head/usr.bin/find/function.c	Sun Mar 17 22:51:58 2013	(r248446)
@@ -238,7 +238,7 @@ nextarg(OPTION *option, char ***argvp)
  */
 #define	TIME_CORRECT(p) \
 	if (((p)->flags & F_ELG_MASK) == F_LESSTHAN) \
-		++((p)->t_data);
+		++((p)->t_data.tv_sec);
 
 /*
  * -[acm]min n functions --
@@ -255,16 +255,16 @@ f_Xmin(PLAN *plan, FTSENT *entry)
 {
 	if (plan->flags & F_TIME_C) {
 		COMPARE((now - entry->fts_statp->st_ctime +
-		    60 - 1) / 60, plan->t_data);
+		    60 - 1) / 60, plan->t_data.tv_sec);
 	} else if (plan->flags & F_TIME_A) {
 		COMPARE((now - entry->fts_statp->st_atime +
-		    60 - 1) / 60, plan->t_data);
+		    60 - 1) / 60, plan->t_data.tv_sec);
 	} else if (plan->flags & F_TIME_B) {
 		COMPARE((now - entry->fts_statp->st_birthtime +
-		    60 - 1) / 60, plan->t_data);
+		    60 - 1) / 60, plan->t_data.tv_sec);
 	} else {
 		COMPARE((now - entry->fts_statp->st_mtime +
-		    60 - 1) / 60, plan->t_data);
+		    60 - 1) / 60, plan->t_data.tv_sec);
 	}
 }
 
@@ -278,7 +278,8 @@ c_Xmin(OPTION *option, char ***argvp)
 	ftsoptions &= ~FTS_NOSTAT;
 
 	new = palloc(option);
-	new->t_data = find_parsenum(new, option->name, nmins, NULL);
+	new->t_data.tv_sec = find_parsenum(new, option->name, nmins, NULL);
+	new->t_data.tv_nsec = 0;
 	TIME_CORRECT(new);
 	return new;
 }
@@ -309,9 +310,9 @@ f_Xtime(PLAN *plan, FTSENT *entry)
 		xtime = entry->fts_statp->st_mtime;
 
 	if (plan->flags & F_EXACTTIME)
-		COMPARE(now - xtime, plan->t_data);
+		COMPARE(now - xtime, plan->t_data.tv_sec);
 	else
-		COMPARE((now - xtime + 86400 - 1) / 86400, plan->t_data);
+		COMPARE((now - xtime + 86400 - 1) / 86400, plan->t_data.tv_sec);
 }
 
 PLAN *
@@ -324,7 +325,8 @@ c_Xtime(OPTION *option, char ***argvp)
 	ftsoptions &= ~FTS_NOSTAT;
 
 	new = palloc(option);
-	new->t_data = find_parsetime(new, option->name, value);
+	new->t_data.tv_sec = find_parsetime(new, option->name, value);
+	new->t_data.tv_nsec = 0;
 	if (!(new->flags & F_EXACTTIME))
 		TIME_CORRECT(new);
 	return new;
@@ -1152,14 +1154,19 @@ c_name(OPTION *option, char ***argvp)
 int
 f_newer(PLAN *plan, FTSENT *entry)
 {
+	struct timespec ft;
+
 	if (plan->flags & F_TIME_C)
-		return entry->fts_statp->st_ctime > plan->t_data;
+		ft = entry->fts_statp->st_ctim;
 	else if (plan->flags & F_TIME_A)
-		return entry->fts_statp->st_atime > plan->t_data;
+		ft = entry->fts_statp->st_atim;
 	else if (plan->flags & F_TIME_B)
-		return entry->fts_statp->st_birthtime > plan->t_data;
+		ft = entry->fts_statp->st_birthtim;
 	else
-		return entry->fts_statp->st_mtime > plan->t_data;
+		ft = entry->fts_statp->st_mtim;
+	return (ft.tv_sec > plan->t_data.tv_sec ||
+	    (ft.tv_sec == plan->t_data.tv_sec &&
+	    ft.tv_nsec > plan->t_data.tv_nsec));
 }
 
 PLAN *
@@ -1175,20 +1182,22 @@ c_newer(OPTION *option, char ***argvp)
 	new = palloc(option);
 	/* compare against what */
 	if (option->flags & F_TIME2_T) {
-		new->t_data = get_date(fn_or_tspec);
-		if (new->t_data == (time_t) -1)
+		new->t_data.tv_sec = get_date(fn_or_tspec);
+		if (new->t_data.tv_sec == (time_t) -1)
 			errx(1, "Can't parse date/time: %s", fn_or_tspec);
+		/* Use the seconds only in the comparison. */
+		new->t_data.tv_nsec = 999999999;
 	} else {
 		if (stat(fn_or_tspec, &sb))
 			err(1, "%s", fn_or_tspec);
 		if (option->flags & F_TIME2_C)
-			new->t_data = sb.st_ctime;
+			new->t_data = sb.st_ctim;
 		else if (option->flags & F_TIME2_A)
-			new->t_data = sb.st_atime;
+			new->t_data = sb.st_atim;
 		else if (option->flags & F_TIME2_B)
-			new->t_data = sb.st_birthtime;
+			new->t_data = sb.st_birthtim;
 		else
-			new->t_data = sb.st_mtime;
+			new->t_data = sb.st_mtim;
 	}
 	return new;
 }


More information about the svn-src-all mailing list