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 | |
parent | f48c5e0c09d4ca4f60a6f0d54ed3c851bb6dce60 (diff) |
From NetBSD:
Add a `-t' (touch) option to update time stamps.
Only record size for regular files.
-rw-r--r-- | usr.sbin/mtree/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/mtree/compare.c | 47 | ||||
-rw-r--r-- | usr.sbin/mtree/create.c | 8 | ||||
-rw-r--r-- | usr.sbin/mtree/mtree.8 | 11 | ||||
-rw-r--r-- | usr.sbin/mtree/mtree.c | 15 | ||||
-rw-r--r-- | usr.sbin/mtree/spec.c | 4 |
6 files changed, 56 insertions, 32 deletions
diff --git a/usr.sbin/mtree/Makefile b/usr.sbin/mtree/Makefile index 7b0e9e26bba..3d3835bd453 100644 --- a/usr.sbin/mtree/Makefile +++ b/usr.sbin/mtree/Makefile @@ -1,5 +1,6 @@ -# $OpenBSD: Makefile,v 1.4 1996/12/10 08:26:53 deraadt Exp $ +# $OpenBSD: Makefile,v 1.5 1997/01/03 21:40:48 millert Exp $ # $NetBSD: Makefile,v 1.8 1995/03/07 21:12:04 cgd Exp $ +# @(#)Makefile 8.1 (Berkeley) 6/6/93 PROG= mtree #CFLAGS+=-DDEBUG 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) { diff --git a/usr.sbin/mtree/create.c b/usr.sbin/mtree/create.c index f869546e0fd..61b9d03de18 100644 --- a/usr.sbin/mtree/create.c +++ b/usr.sbin/mtree/create.c @@ -1,5 +1,5 @@ -/* $NetBSD: create.c,v 1.9 1995/03/07 21:12:06 cgd Exp $ */ -/* $OpenBSD: create.c,v 1.4 1996/12/10 08:25:58 deraadt Exp $ */ +/* $NetBSD: create.c,v 1.11 1996/09/05 09:24:19 mycroft Exp $ */ +/* $OpenBSD: create.c,v 1.5 1997/01/03 21:40:49 millert Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$NetBSD: create.c,v 1.9 1995/03/07 21:12:06 cgd Exp $"; +static char rcsid[] = "$OpenBSD: create.c,v 1.5 1997/01/03 21:40:49 millert Exp $"; #endif #endif /* not lint */ @@ -182,7 +182,7 @@ statf(indent, p) output(indent, &offset, "mode=%#o", p->fts_statp->st_mode & MBITS); if (keys & F_NLINK && p->fts_statp->st_nlink != 1) output(indent, &offset, "nlink=%u", p->fts_statp->st_nlink); - if (keys & F_SIZE) + if (keys & F_SIZE && S_ISREG(p->fts_statp->st_mode)) output(indent, &offset, "size=%qd", p->fts_statp->st_size); if (keys & F_TIME) output(indent, &offset, "time=%ld.%ld", diff --git a/usr.sbin/mtree/mtree.8 b/usr.sbin/mtree/mtree.8 index a2ca1149698..266769419e9 100644 --- a/usr.sbin/mtree/mtree.8 +++ b/usr.sbin/mtree/mtree.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mtree.8,v 1.4 1996/12/20 18:13:42 millert Exp $ +.\" $OpenBSD: mtree.8,v 1.5 1997/01/03 21:40:50 millert Exp $ .\" $NetBSD: mtree.8,v 1.4 1995/03/07 21:26:25 cgd Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 @@ -103,6 +103,9 @@ of the files for which the keyword .Cm cksum was specified. The checksum is seeded with the specified value. +.It Fl t +If a file's timestamp is different from the specification, +``touch'' it to match the specification (and list as modified). .It Fl U Modify the owner, group, and permissions of existing files to match the specification and create any missing directories. @@ -111,10 +114,10 @@ to be created. Exit with a status of 0 on success, 1 if any error occurred, a mismatch is not considered an error if it was corrected. .It Fl u -Same as +Same as the .Fl U -except a status of 2 is returned if the file hierarchy did not match -the specification. +option except a status of 2 is returned if the file hierarchy +did not match the specification. .It Fl x Don't descend below mount points in the file hierarchy. .El diff --git a/usr.sbin/mtree/mtree.c b/usr.sbin/mtree/mtree.c index f7609875de4..fb2423c5f12 100644 --- a/usr.sbin/mtree/mtree.c +++ b/usr.sbin/mtree/mtree.c @@ -1,5 +1,5 @@ -/* $OpenBSD: mtree.c,v 1.3 1996/12/10 08:26:09 deraadt Exp $ */ -/* $NetBSD: mtree.c,v 1.5 1995/03/07 21:12:10 cgd Exp $ */ +/* $OpenBSD: mtree.c,v 1.4 1997/01/03 21:40:50 millert Exp $ */ +/* $NetBSD: mtree.c,v 1.7 1996/09/05 23:29:22 thorpej Exp $ */ /*- * Copyright (c) 1989, 1990, 1993 @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)mtree.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: mtree.c,v 1.3 1996/12/10 08:26:09 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: mtree.c,v 1.4 1997/01/03 21:40:50 millert Exp $"; #endif #endif /* not lint */ @@ -60,7 +60,7 @@ static char rcsid[] = "$OpenBSD: mtree.c,v 1.3 1996/12/10 08:26:09 deraadt Exp $ extern u_int32_t crc_total; int ftsoptions = FTS_PHYSICAL; -int cflag, dflag, eflag, iflag, nflag, rflag, sflag, uflag, Uflag; +int cflag, dflag, eflag, iflag, nflag, rflag, sflag, tflag, uflag, Uflag; u_short keys; char fullpath[MAXPATHLEN]; @@ -79,7 +79,7 @@ main(argc, argv) dir = NULL; keys = KEYDEFAULT; - while ((ch = getopt(argc, argv, "cdef:iK:k:np:rs:Uux")) != EOF) + while ((ch = getopt(argc, argv, "cdef:iK:k:np:rs:tUux")) != EOF) switch((char)ch) { case 'c': cflag = 1; @@ -122,6 +122,9 @@ main(argc, argv) crc_total = ~strtol(optarg, &p, 0); if (*p) err("illegal seed value -- %s", optarg); + case 't': + tflag = 1; + break; case 'U': Uflag = 1; uflag = 1; @@ -162,6 +165,6 @@ static void usage() { (void)fprintf(stderr, -"usage: mtree [-cdeinrUux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n"); +"usage: mtree [-cdeinrtUux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n"); exit(1); } diff --git a/usr.sbin/mtree/spec.c b/usr.sbin/mtree/spec.c index 7686b28a4b1..70f1cb5246e 100644 --- a/usr.sbin/mtree/spec.c +++ b/usr.sbin/mtree/spec.c @@ -1,5 +1,5 @@ /* $NetBSD: spec.c,v 1.6 1995/03/07 21:12:12 cgd Exp $ */ -/* $OpenBSD: spec.c,v 1.4 1996/12/20 18:13:44 millert Exp $ */ +/* $OpenBSD: spec.c,v 1.5 1997/01/03 21:40:51 millert Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)spec.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$NetBSD: spec.c,v 1.6 1995/03/07 21:12:12 cgd Exp $"; +static char rcsid[] = "$OpenBSD: spec.c,v 1.5 1997/01/03 21:40:51 millert Exp $"; #endif #endif /* not lint */ |