aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/find
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2013-03-17 22:51:58 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2013-03-17 22:51:58 +0000
commitddd956b0b7f7484b1a65bd4ec854c12de1bafa78 (patch)
treeacb41cfcc47f74460505dadbb11a5025aede736f /usr.bin/find
parentb479b38c0a2bac100921e8130224a5d4eac6ab1b (diff)
downloadsrc-ddd956b0b7f7484b1a65bd4ec854c12de1bafa78.tar.gz
src-ddd956b0b7f7484b1a65bd4ec854c12de1bafa78.zip
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
Notes
Notes: svn path=/head/; revision=248446
Diffstat (limited to 'usr.bin/find')
-rw-r--r--usr.bin/find/find.h2
-rw-r--r--usr.bin/find/function.c47
2 files changed, 29 insertions, 20 deletions
diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h
index f602707971f5..53cb69ff2f77 100644
--- a/usr.bin/find/find.h
+++ b/usr.bin/find/find.h
@@ -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 */
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index 61d61cb49077..7f16a8f1892a 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -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;
}