From owner-svn-src-head@FreeBSD.ORG Sun Mar 17 22:51:59 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 3A70D972; Sun, 17 Mar 2013 22:51:59 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 147C07A1; Sun, 17 Mar 2013 22:51:59 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r2HMpwjW085041; Sun, 17 Mar 2013 22:51:58 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r2HMpw9U085037; Sun, 17 Mar 2013 22:51:58 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201303172251.r2HMpw9U085037@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 17 Mar 2013 22:51:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r248446 - head/usr.bin/find X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Mar 2013 22:51:59 -0000 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; }