Add a `-t' (touch) option to update time stamps.
Only record size for regular files.
-# $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
-/* $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
#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 */
#include "mtree.h"
#include "extern.h"
-extern int uflag;
+extern int tflag, uflag;
static char *ftype __P((u_int));
register NODE *s;
register FTSENT *p;
{
- extern int uflag;
u_int32_t len, val;
int fd, label;
char *cp, *tab = "";
}
/*
* 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) {
-/* $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
#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 */
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",
-.\" $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
.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.
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
-/* $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
#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 */
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];
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;
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;
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);
}
/* $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
#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 */