- use lch*() instead of ch*() to change permissions, so that links in

the specfile don't confuse things.  doesn't affect the default
  (physical) operation, and shouldn't affect logical either.
- slightly rework how miss() is implemented so that duplicated code is
  reduced and links may optionally have a mode, uname and/or gname.
This commit is contained in:
lukem 2002-02-04 07:17:14 +00:00
parent 0719c73e2a
commit f93e02f7db
2 changed files with 39 additions and 47 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: compare.c,v 1.38 2002/01/31 19:37:15 tv Exp $ */
/* $NetBSD: compare.c,v 1.39 2002/02/04 07:17:14 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.38 2002/01/31 19:37:15 tv Exp $");
__RCSID("$NetBSD: compare.c,v 1.39 2002/02/04 07:17:14 lukem Exp $");
#endif
#endif /* not lint */
@ -84,7 +84,7 @@ do { \
printf("%sflags (\"%s\"", tab, \
flags_to_string(p->fts_statp->st_flags, "none")); \
} \
if (chflags(path, flags)) { \
if (lchflags(path, flags)) { \
label++; \
printf(", not modified: %s)\n", \
strerror(errno)); \
@ -96,7 +96,7 @@ do { \
/* SETFLAGS:
* given pflags, additionally set those flags specified in sflags and
* selected by mask (the other flags are left unchanged). oflags is
* passed as reference to check if chflags is necessary.
* passed as reference to check if lchflags is necessary.
*/
#define SETFLAGS(path, sflags, pflags, oflags, mask) \
do { \
@ -107,7 +107,7 @@ do { \
/* CLEARFLAGS:
* given pflags, reset the flags specified in sflags and selected by mask
* (the other flags are left unchanged). oflags is
* passed as reference to check if chflags is necessary.
* passed as reference to check if lchflags is necessary.
*/
#define CLEARFLAGS(path, sflags, pflags, oflags, mask) \
do { \
@ -190,7 +190,7 @@ compare(NODE *s, FTSENT *p)
(mknod(p->fts_accpath,
s->st_mode | nodetoino(s->type),
s->st_rdev) == -1) ||
(chown(p->fts_accpath, p->fts_statp->st_uid,
(lchown(p->fts_accpath, p->fts_statp->st_uid,
p->fts_statp->st_gid) == -1) )
printf(", not modified: %s)\n",
strerror(errno));
@ -206,7 +206,7 @@ compare(NODE *s, FTSENT *p)
printf("%suser (%lu, %lu",
tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid);
if (uflag) {
if (chown(p->fts_accpath, s->st_uid, -1))
if (lchown(p->fts_accpath, s->st_uid, -1))
printf(", not modified: %s)\n",
strerror(errno));
else
@ -220,7 +220,7 @@ compare(NODE *s, FTSENT *p)
printf("%sgid (%lu, %lu",
tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid);
if (uflag) {
if (chown(p->fts_accpath, -1, s->st_gid))
if (lchown(p->fts_accpath, -1, s->st_gid))
printf(", not modified: %s)\n",
strerror(errno));
else
@ -253,7 +253,7 @@ compare(NODE *s, FTSENT *p)
tab, (u_long)s->st_mode,
(u_long)p->fts_statp->st_mode & MBITS);
if (uflag) {
if (chmod(p->fts_accpath, s->st_mode))
if (lchmod(p->fts_accpath, s->st_mode))
printf(", not modified: %s)\n",
strerror(errno));
else
@ -326,7 +326,7 @@ compare(NODE *s, FTSENT *p)
#if HAVE_STRUCT_STAT_ST_FLAGS
/*
* XXX
* since chflags(2) will reset file times, the utimes() above
* since lchflags(2) will reset file times, the utimes() above
* may have been useless! oh well, we'd rather have correct
* flags, rather than times?
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: verify.c,v 1.28 2002/02/04 05:16:41 lukem Exp $ */
/* $NetBSD: verify.c,v 1.29 2002/02/04 07:17:14 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.28 2002/02/04 05:16:41 lukem Exp $");
__RCSID("$NetBSD: verify.c,v 1.29 2002/02/04 07:17:14 lukem Exp $");
#endif
#endif /* not lint */
@ -191,19 +191,19 @@ miss(NODE *p, char *tail)
create = 0;
if (!(p->flags & F_VISIT) && uflag) {
if (Wflag)
goto makeit;
if (Wflag || p->type == F_LINK)
goto createit;
if (!(p->flags & (F_UID | F_UNAME)))
printf(
" (%s not created: user not specified)", type);
else if (!(p->flags & (F_GID | F_GNAME)))
printf(
" (%s not created: group not specified)", type);
else if (!(p->flags & F_MODE) && p->type != F_LINK)
else if (!(p->flags & F_MODE))
printf(
" (%s not created: mode not specified)", type);
else
makeit:
createit:
switch (p->type) {
case F_BLOCK:
case F_CHAR:
@ -219,65 +219,57 @@ miss(NODE *p, char *tail)
printf(" (%s not created: %s)\n",
type, strerror(errno));
else
printf(" (created)\n");
if (chown(path, p->st_uid, p->st_gid))
printf(
"%s: user/group not modified: %s\n",
path, strerror(errno));
if (chmod(path, p->st_mode))
printf("%s: permissions not set: %s\n",
path, strerror(errno));
continue;
create = 1;
break;
case F_LINK:
if (!(p->flags & F_LINK))
if (!(p->flags & F_SLINK))
printf(
" (%s not created: link not specified)",
" (%s not created: link not specified)\n",
type);
else if (symlink(p->slink, path))
printf(
" (%s not created: %s)\n",
type, strerror(errno));
else
printf(" (created)\n");
if (!Wflag &&
lchown(path, p->st_uid, p->st_gid))
printf(
"%s: user/group not modified: %s\n",
path, strerror(errno));
continue;
create = 1;
break;
case F_DIR:
if (mkdir(path, S_IRWXU))
printf(" (not created: %s)",
strerror(errno));
else {
else
create = 1;
printf(" (created)");
}
break;
default:
mtree_err("can't create create %s",
nodetype(p->type));
}
}
if (!(p->flags & F_VISIT))
if (create)
printf(" (created)");
if (p->type == F_DIR) {
if (!(p->flags & F_VISIT))
putchar('\n');
for (tp = tail; *tp; ++tp)
continue;
*tp = '/';
miss(p->child, tp + 1);
*tp = '\0';
} else
putchar('\n');
for (tp = tail; *tp; ++tp)
continue;
*tp = '/';
miss(p->child, tp + 1);
*tp = '\0';
if (!create || Wflag)
continue;
if (chown(path, p->st_uid, p->st_gid)) {
if ((p->flags & (F_UID | F_UNAME)) &&
(p->flags & (F_GID | F_GNAME)) &&
(lchown(path, p->st_uid, p->st_gid))) {
printf("%s: user/group/mode not modified: %s\n",
path, strerror(errno));
printf("%s: warning: file mode %snot set\n", path,
(p->flags & F_FLAGS) ? "and file flags " : "");
continue;
}
if (chmod(path, p->st_mode))
if ((p->flags & F_MODE) && lchmod(path, p->st_mode))
printf("%s: permissions not set: %s\n",
path, strerror(errno));
#if HAVE_STRUCT_STAT_ST_FLAGS
@ -286,7 +278,7 @@ miss(NODE *p, char *tail)
flags = p->st_flags;
else
flags = p->st_flags & ~SP_FLGS;
if (chflags(path, flags))
if (lchflags(path, flags))
printf("%s: file flags not set: %s\n",
path, strerror(errno));
}