Add -W: don't attempt to change the perms/time/flags on existing entries, nor

set them when creating new directories. (AKA the ``don't whack'' option).
Concept suggested by Todd Vierling.
This commit is contained in:
lukem 2001-10-25 14:47:39 +00:00
parent 59121d58f5
commit 1e617f29fb
5 changed files with 42 additions and 17 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: compare.c,v 1.32 2001/10/22 07:07:46 lukem Exp $ */
/* $NetBSD: compare.c,v 1.33 2001/10/25 14:47:39 lukem Exp $ */
/*-
* Copyright (c) 1989, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: compare.c,v 1.32 2001/10/22 07:07:46 lukem Exp $");
__RCSID("$NetBSD: compare.c,v 1.33 2001/10/25 14:47:39 lukem Exp $");
#endif
#endif /* not lint */
@ -151,6 +151,8 @@ typeerr: LABEL;
}
break;
}
if (Wflag)
goto afterpermwhack;
if (iflag && !uflag) {
if (s->flags & F_FLAGS)
SETFLAGS(p->fts_accpath, s->st_flags,
@ -333,6 +335,12 @@ typeerr: LABEL;
(void)printf(")\n");
tab = "\t";
}
/*
* from this point, no more permission checking or whacking
* occurs, only checking of stuff like checksums and symlinks.
*/
afterpermwhack:
if (s->flags & F_CKSUM) {
if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) {
LABEL;

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.16 2001/10/25 03:00:14 lukem Exp $ */
/* $NetBSD: extern.h,v 1.17 2001/10/25 14:47:39 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -53,6 +53,7 @@ const char *rlink(const char *);
int verify(void);
extern int dflag, eflag, iflag, lflag, mflag, rflag, sflag, tflag, uflag;
extern int Wflag;
extern size_t lineno;
extern int crc_total, ftsoptions, keys;
extern char fullpath[];

View File

@ -1,4 +1,4 @@
.\" $NetBSD: mtree.8,v 1.25 2001/10/22 07:11:46 lukem Exp $
.\" $NetBSD: mtree.8,v 1.26 2001/10/25 14:47:39 lukem Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -33,7 +33,7 @@
.\"
.\" @(#)mtree.8 8.2 (Berkeley) 12/11/93
.\"
.Dd October 22, 2001
.Dd October 26, 2001
.Dt MTREE 8
.Os
.Sh NAME
@ -41,7 +41,7 @@
.Nd map a directory hierarchy
.Sh SYNOPSIS
.Nm ""
.Op Fl cdDelrUux
.Op Fl cdDelrUuWx
.Bk -words
.Op Fl i | Fl m
.Ek
@ -195,6 +195,14 @@ Same as
.Fl U
except a status of 2 is returned if the file hierarchy did not match
the specification.
.It Fl W
Don't attempt to set various file attributes such as the
ownership, mode, flags, or time
when creating new directories or changing existing entries.
This option will be most useful when used in conjunction with
.Fl u
or
.Fl U .
.It Fl x
Don't descend below mount points in the file hierarchy.
.El
@ -528,8 +536,9 @@ keywords,
.Fl l ,
.Fl D ,
.Fl E ,
.Fl I
.Fl I ,
.Fl R ,
and
.Fl R
.Fl W
flags, and support for full paths appeared in
.Nx 1.6 .

View File

@ -1,4 +1,4 @@
/* $NetBSD: mtree.c,v 1.21 2001/10/22 07:07:46 lukem Exp $ */
/* $NetBSD: mtree.c,v 1.22 2001/10/25 14:47:39 lukem Exp $ */
/*-
* Copyright (c) 1989, 1990, 1993
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1990, 1993\n\
#if 0
static char sccsid[] = "@(#)mtree.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: mtree.c,v 1.21 2001/10/22 07:07:46 lukem Exp $");
__RCSID("$NetBSD: mtree.c,v 1.22 2001/10/25 14:47:39 lukem Exp $");
#endif
#endif /* not lint */
@ -62,7 +62,7 @@ __RCSID("$NetBSD: mtree.c,v 1.21 2001/10/22 07:07:46 lukem Exp $");
int ftsoptions = FTS_PHYSICAL;
int cflag, dflag, Dflag, eflag, iflag, lflag, mflag,
rflag, sflag, tflag, uflag, Uflag;
rflag, sflag, tflag, uflag, Uflag, Wflag;
char fullpath[MAXPATHLEN];
int main(int, char **);
@ -77,7 +77,7 @@ main(int argc, char **argv)
setprogname(argv[0]);
dir = NULL;
while ((ch = getopt(argc, argv, "cdDeE:f:I:iK:k:lmp:rR:s:tUux")) != -1)
while ((ch = getopt(argc, argv, "cdDeE:f:I:iK:k:lmp:rR:s:tUuWx")) != -1)
switch((char)ch) {
case 'c':
cflag = 1;
@ -147,6 +147,9 @@ main(int argc, char **argv)
case 'u':
uflag = 1;
break;
case 'W':
Wflag = 1;
break;
case 'x':
ftsoptions |= FTS_XDEV;
break;
@ -193,7 +196,7 @@ static void
usage(void)
{
(void)fprintf(stderr, "usage: mtree [-cdDelrUux] [-i|-m] [-f spec]"
(void)fprintf(stderr, "usage: mtree [-cdDelrUuWx] [-i|-m] [-f spec]"
" [-k key] [-K addkey] [-R removekey]\n"
"\t\t[-I inctags] [-E exctags] [-p path] [-s seed]\n");
exit(1);

View File

@ -1,4 +1,4 @@
/* $NetBSD: verify.c,v 1.22 2001/10/22 07:07:46 lukem Exp $ */
/* $NetBSD: verify.c,v 1.23 2001/10/25 14:47:39 lukem Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)verify.c 8.1 (Berkeley) 6/6/93";
#else
__RCSID("$NetBSD: verify.c,v 1.22 2001/10/22 07:07:46 lukem Exp $");
__RCSID("$NetBSD: verify.c,v 1.23 2001/10/25 14:47:39 lukem Exp $");
#endif
#endif /* not lint */
@ -172,13 +172,17 @@ miss(NODE *p, char *tail)
create = 0;
if (!(p->flags & F_VISIT) && uflag) {
if (Wflag)
goto makeit;
if (!(p->flags & (F_UID | F_UNAME)))
(void)printf(" (not created: user not specified)");
else if (!(p->flags & (F_GID | F_GNAME)))
(void)printf(" (not created: group not specified)");
else if (!(p->flags & F_MODE))
(void)printf(" (not created: mode not specified)");
else if (mkdir(path, S_IRWXU))
else
makeit:
if (mkdir(path, S_IRWXU))
(void)printf(" (not created: %s)",
strerror(errno));
else {
@ -195,7 +199,7 @@ miss(NODE *p, char *tail)
miss(p->child, tp + 1);
*tp = '\0';
if (!create)
if (!create || Wflag)
continue;
/* XXXLUKEM: what about devices? */
if (chown(path, p->st_uid, p->st_gid)) {