Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/mtree - implement -D - dump the specfile out in a ...



details:   https://anonhg.NetBSD.org/src/rev/edff1834392e
branches:  trunk
changeset: 515658:edff1834392e
user:      lukem <lukem%NetBSD.org@localhost>
date:      Mon Oct 01 02:30:40 2001 +0000

description:
- implement -D  - dump the specfile out in a manner that's parseable
  by various tools
- implement -R key  - remove the given key(s) from the list of keys to print
  (now it's possible with "-k type -R type" to remove all keys :)
- rename ftype() to nodetype(), and make it public
- use pwcache(3) functions instead of get{gr,pw}{nam,uid}(3)
- add dump_nodes(), which provides the guts for -D.

diffstat:

 usr.sbin/mtree/compare.c |  14 ++++-----
 usr.sbin/mtree/create.c  |  28 +++++++++---------
 usr.sbin/mtree/extern.h  |   4 ++-
 usr.sbin/mtree/mtree.8   |  28 ++++++++++++++++---
 usr.sbin/mtree/mtree.c   |  35 +++++++++++++++++-------
 usr.sbin/mtree/spec.c    |  68 +++++++++++++++++++++++++++++++++++++++++------
 6 files changed, 130 insertions(+), 47 deletions(-)

diffs (truncated from 438 to 300 lines):

diff -r 6c3e0f763fad -r edff1834392e usr.sbin/mtree/compare.c
--- a/usr.sbin/mtree/compare.c  Mon Oct 01 02:21:20 2001 +0000
+++ b/usr.sbin/mtree/compare.c  Mon Oct 01 02:30:40 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compare.c,v 1.26 2001/09/22 03:56:29 perry Exp $       */
+/*     $NetBSD: compare.c,v 1.27 2001/10/01 02:30:40 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.26 2001/09/22 03:56:29 perry Exp $");
+__RCSID("$NetBSD: compare.c,v 1.27 2001/10/01 02:30:40 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -59,8 +59,6 @@
 
 extern int iflag, lflag, mflag, tflag, uflag;
 
-static const char *ftype(u_int);
-
 #define        INDENTNAMELEN   8
 #define MARK                                                                  \
 do {                                                                          \
@@ -153,7 +151,7 @@
                if (!S_ISSOCK(p->fts_statp->st_mode)) {
 typeerr:               LABEL;
                        (void)printf("\ttype (%s, %s)\n",
-                           ftype(s->type), inotype(p->fts_statp->st_mode));
+                           nodetype(s->type), inotype(p->fts_statp->st_mode));
                }
                break;
        }
@@ -371,11 +369,11 @@
 inotype(u_int type)
 {
 
-       return (ftype(type & S_IFMT));
+       return (nodetype(type & S_IFMT));
 }
 
-static const char *
-ftype(u_int type)
+const char *
+nodetype(u_int type)
 {
 
        switch(type) {
diff -r 6c3e0f763fad -r edff1834392e usr.sbin/mtree/create.c
--- a/usr.sbin/mtree/create.c   Mon Oct 01 02:21:20 2001 +0000
+++ b/usr.sbin/mtree/create.c   Mon Oct 01 02:30:40 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: create.c,v 1.29 2001/03/09 03:09:45 simonb Exp $       */
+/*     $NetBSD: create.c,v 1.30 2001/10/01 02:30:40 lukem Exp $        */
 
 /*-
  * Copyright (c) 1989, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)create.c   8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: create.c,v 1.29 2001/03/09 03:09:45 simonb Exp $");
+__RCSID("$NetBSD: create.c,v 1.30 2001/10/01 02:30:40 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -135,11 +135,10 @@
 static void
 statf(FTSENT *p)
 {
-       struct group *gr;
-       struct passwd *pw;
        u_int32_t len, val;
        int fd, indent;
        char md5buf[33], *md5cp;
+       const char *name;
 
        strsvis(codebuf, p->fts_name, VISFLAGS, extra);
        if (S_ISDIR(p->fts_statp->st_mode))
@@ -155,14 +154,16 @@
        if (!S_ISREG(p->fts_statp->st_mode))
                output(&indent, "type=%s", inotype(p->fts_statp->st_mode));
        if (keys & (F_UID | F_UNAME) && p->fts_statp->st_uid != uid) {
-               if (keys & F_UNAME && (pw = getpwuid(p->fts_statp->st_uid)))
-                       output(&indent, "uname=%s", pw->pw_name);
+               if (keys & F_UNAME &&
+                   (name = user_from_uid(p->fts_statp->st_uid, 1)) != NULL)
+                       output(&indent, "uname=%s", name);
                else /* if (keys & F_UID) */
                        output(&indent, "uid=%u", p->fts_statp->st_uid);
        }
        if (keys & (F_GID | F_GNAME) && p->fts_statp->st_gid != gid) {
-               if (keys & F_GNAME && (gr = getgrgid(p->fts_statp->st_gid)))
-                       output(&indent, "gname=%s", gr->gr_name);
+               if (keys & F_GNAME &&
+                   (name = group_from_gid(p->fts_statp->st_gid, 1)) != NULL)
+                       output(&indent, "gname=%s", name);
                else /* if (keys & F_GID) */
                        output(&indent, "gid=%u", p->fts_statp->st_gid);
        }
@@ -223,8 +224,7 @@
        uid_t suid;
        mode_t smode;
        u_long sflags;
-       struct group *gr;
-       struct passwd *pw;
+       const char *name;
        gid_t savegid;
        uid_t saveuid;
        mode_t savemode;
@@ -276,14 +276,14 @@
        if (keys & F_GID)
                (void)printf(" gid=%lu", (u_long)savegid);
        if (keys & F_GNAME) {
-               if ((gr = getgrgid(savegid)) != NULL)
-                       (void)printf(" gname=%s", gr->gr_name);
+               if ((name = group_from_gid(savegid, 1)) != NULL)
+                       (void)printf(" gname=%s", name);
                else
                        (void)printf(" gid=%lu", (u_long)savegid);
        }
        if (keys & F_UNAME) {
-               if ((pw = getpwuid(saveuid)) != NULL)
-                       (void)printf(" uname=%s", pw->pw_name);
+               if ((name = user_from_uid(saveuid, 1)) != NULL)
+                       (void)printf(" uname=%s", name);
                else
                        (void)printf(" uid=%lu", (u_long)saveuid);
        }
diff -r 6c3e0f763fad -r edff1834392e usr.sbin/mtree/extern.h
--- a/usr.sbin/mtree/extern.h   Mon Oct 01 02:21:20 2001 +0000
+++ b/usr.sbin/mtree/extern.h   Mon Oct 01 02:30:40 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.11 2001/07/18 04:51:54 lukem Exp $        */
+/*     $NetBSD: extern.h,v 1.12 2001/10/01 02:30:40 lukem Exp $        */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,9 +40,11 @@
 int     compare(const char *, NODE *, FTSENT *);
 int     crc(int, u_int32_t *, u_int32_t *);
 void    cwalk(void);
+void   dump_nodes(const char *, NODE *);
 void    mtree_err(const char *, ...)
        __attribute__((__format__(__printf__, 1, 2)));
 const char *inotype(u_int);
+const char *nodetype(u_int);
 u_int   parsekey(const char *, int *);
 u_int   parsetype(const char *);
 const char *rlink(const char *);
diff -r 6c3e0f763fad -r edff1834392e usr.sbin/mtree/mtree.8
--- a/usr.sbin/mtree/mtree.8    Mon Oct 01 02:21:20 2001 +0000
+++ b/usr.sbin/mtree/mtree.8    Mon Oct 01 02:30:40 2001 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mtree.8,v 1.15 2001/09/22 03:56:29 perry Exp $
+.\"    $NetBSD: mtree.8,v 1.16 2001/10/01 02:30:40 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 December 11, 1993
+.Dd October 1, 2001
 .Dt MTREE 8
 .Os
 .Sh NAME
@@ -41,7 +41,7 @@
 .Nd map a directory hierarchy
 .Sh SYNOPSIS
 .Nm ""
-.Op Fl cdelrUux
+.Op Fl cdDelrUux
 .Bk -words
 .Op Fl i | Fl m
 .Ek
@@ -49,13 +49,16 @@
 .Op Fl f Ar spec
 .Ek
 .Bk -words
-.Op Fl K Ar keywords
+.Op Fl p Ar path
 .Ek
 .Bk -words
 .Op Fl k Ar keywords
 .Ek
 .Bk -words
-.Op Fl p Ar path
+.Op Fl K Ar keywords
+.Ek
+.Bk -words
+.Op Fl R Ar keywords
 .Ek
 .Bk -words
 .Op Fl s Ar seed
@@ -75,6 +78,18 @@
 Print a specification for the file hierarchy to the standard output.
 .It Fl d
 Ignore everything except directory type files.
+.It Fl D
+Print
+.Pq Sq dump
+the specification as provided by
+.Fl f Ar spec
+in a format that's easier to parse with various tools.
+The name is always printed as the last field, and
+.Fl k ,
+.Fl K ,
+and
+.Fl R
+can be used to control which other keywords are printed.
 .It Fl e
 Don't complain about files that are in the file hierarchy, but not in the
 specification.
@@ -118,6 +133,9 @@
 .It Fl r
 Remove any files in the file hierarchy that are not described in the
 specification.
+.It Fl R
+Remove the specified (whitespace or comma separated) keywords from the current
+set of keywords.
 .It Fl s
 Display a single checksum to the standard error output that represents all
 of the files for which the keyword
diff -r 6c3e0f763fad -r edff1834392e usr.sbin/mtree/mtree.c
--- a/usr.sbin/mtree/mtree.c    Mon Oct 01 02:21:20 2001 +0000
+++ b/usr.sbin/mtree/mtree.c    Mon Oct 01 02:30:40 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mtree.c,v 1.17 2001/09/22 03:56:29 perry Exp $ */
+/*     $NetBSD: mtree.c,v 1.18 2001/10/01 02:30:40 lukem Exp $ */
 
 /*-
  * Copyright (c) 1989, 1990, 1993
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)mtree.c    8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: mtree.c,v 1.17 2001/09/22 03:56:29 perry Exp $");
+__RCSID("$NetBSD: mtree.c,v 1.18 2001/10/01 02:30:40 lukem Exp $");
 #endif
 #endif /* not lint */
 
@@ -60,11 +60,11 @@
 
 extern int crc_total;
 
-int ftsoptions = FTS_PHYSICAL;
-int cflag, dflag, eflag, iflag, lflag, mflag,
-    rflag, sflag, tflag, uflag, Uflag;
-int keys;
-char fullpath[MAXPATHLEN];
+int    ftsoptions = FTS_PHYSICAL;
+int    cflag, dflag, Dflag, eflag, iflag, lflag, mflag,
+       rflag, sflag, tflag, uflag, Uflag;
+int    keys;
+char   fullpath[MAXPATHLEN];
 
        int     main(int, char **);
 static void    usage(void);
@@ -80,7 +80,7 @@
 
        dir = NULL;
        keys = KEYDEFAULT;
-       while ((ch = getopt(argc, argv, "cdef:iK:k:lmp:rs:tUux")) != -1)
+       while ((ch = getopt(argc, argv, "cdDef:iK:k:lmp:rR:s:tUux")) != -1)
                switch((char)ch) {
                case 'c':
                        cflag = 1;
@@ -88,6 +88,9 @@
                case 'd':
                        dflag = 1;
                        break;
+               case 'D':
+                       Dflag = 1;
+                       break;
                case 'e':
                        eflag = 1;
                        break;
@@ -121,6 +124,11 @@
                case 'r':
                        rflag = 1;
                        break;
+               case 'R':
+                       while ((p = strsep(&optarg, " \t,")) != NULL)
+                               if (*p != '\0')
+                                       keys &= ~parsekey(p, NULL);
+                       break;
                case 's':
                        sflag = 1;
                        crc_total = ~strtol(optarg, &p, 0);
@@ -155,6 +163,9 @@
        if ((cflag || sflag) && !getcwd(fullpath, MAXPATHLEN))
                mtree_err("%s", strerror(errno));
 
+       if (cflag == 1 && Dflag == 1)
+               mtree_err("-c and -D flags are mutually exclusive");



Home | Main Index | Thread Index | Old Index