diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-01-03 21:40:52 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-01-03 21:40:52 +0000 |
commit | b3e85814e581c12d86755a6215992e1cbb47a912 (patch) | |
tree | e168b392dcd7faf2f7e15fba307425b4d2d091b2 /usr.sbin/mtree/compare.c | |
parent | f48c5e0c09d4ca4f60a6f0d54ed3c851bb6dce60 (diff) |
From NetBSD:
Add a `-t' (touch) option to update time stamps.
Only record size for regular files.
Diffstat (limited to 'usr.sbin/mtree/compare.c')
-rw-r--r-- | usr.sbin/mtree/compare.c | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/usr.sbin/mtree/compare.c b/usr.sbin/mtree/compare.c index 71600548733..81d6cd5e0ef 100644 --- a/usr.sbin/mtree/compare.c +++ b/usr.sbin/mtree/compare.c @@ -1,5 +1,5 @@ -/* $NetBSD: compare.c,v 1.9 1995/10/22 20:12:07 pk Exp $ */ -/* $OpenBSD: compare.c,v 1.5 1996/12/10 08:25:57 deraadt Exp $ */ +/* $NetBSD: compare.c,v 1.11 1996/09/05 09:56:48 mycroft Exp $ */ +/* $OpenBSD: compare.c,v 1.6 1997/01/03 21:40:48 millert Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$NetBSD: compare.c,v 1.9 1995/10/22 20:12:07 pk Exp $"; +static char rcsid[] = "$OpenBSD: compare.c,v 1.6 1997/01/03 21:40:48 millert Exp $"; #endif #endif /* not lint */ @@ -54,7 +54,7 @@ static char rcsid[] = "$NetBSD: compare.c,v 1.9 1995/10/22 20:12:07 pk Exp $"; #include "mtree.h" #include "extern.h" -extern int uflag; +extern int tflag, uflag; static char *ftype __P((u_int)); @@ -77,7 +77,6 @@ compare(name, s, p) register NODE *s; register FTSENT *p; { - extern int uflag; u_int32_t len, val; int fd, label; char *cp, *tab = ""; @@ -175,17 +174,35 @@ typeerr: LABEL; } /* * XXX - * Catches nano-second differences, but doesn't display them. + * Since utimes(2) only takes a timeval, there's no point in + * comparing the low bits of the timespec nanosecond field. This + * will only result in mismatches that we can never fix. + * + * Doesn't display microsecond differences. */ - if ((s->flags & F_TIME) && - ((s->st_mtimespec.tv_sec != p->fts_statp->st_mtimespec.tv_sec) || - (s->st_mtimespec.tv_nsec != p->fts_statp->st_mtimespec.tv_nsec))) { - LABEL; - (void)printf("%smodification time (%.24s, ", - tab, ctime(&s->st_mtimespec.tv_sec)); - (void)printf("%.24s)\n", - ctime(&p->fts_statp->st_mtimespec.tv_sec)); - tab = "\t"; + if (s->flags & F_TIME) { + struct timeval tv[2]; + + TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec); + TIMESPEC_TO_TIMEVAL(&tv[1], &p->fts_statp->st_mtimespec); + if (tv[0].tv_sec != tv[1].tv_sec || + tv[0].tv_usec != tv[1].tv_usec) { + LABEL; + (void)printf("%smodification time (%.24s, ", + tab, ctime(&s->st_mtimespec.tv_sec)); + (void)printf("%.24s", + ctime(&p->fts_statp->st_mtimespec.tv_sec)); + if (tflag) { + tv[1] = tv[0]; + if (utimes(p->fts_accpath, tv)) + (void)printf(", not modified: %s)\n", + strerror(errno)); + else + (void)printf(", modified)\n"); + } else + (void)printf(")\n"); + tab = "\t"; + } } if (s->flags & F_CKSUM) if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) { |