svn commit: r240786 - projects/mtree/contrib/mtree
Brooks Davis
brooks at FreeBSD.org
Fri Sep 21 19:26:22 UTC 2012
Author: brooks
Date: Fri Sep 21 19:26:21 2012
New Revision: 240786
URL: http://svn.freebsd.org/changeset/base/240786
Log:
Implement the ability to compare two spec files with -f spec1 -f spec2.
Obtained from: FreeBSD (phk)
Added:
projects/mtree/contrib/mtree/specspec.c (contents, props changed)
- copied, changed from r240785, projects/mtree/usr.sbin/mtree/specspec.c
Modified:
projects/mtree/contrib/mtree/Makefile
projects/mtree/contrib/mtree/extern.h
projects/mtree/contrib/mtree/mtree.c
projects/mtree/contrib/mtree/mtree.h
projects/mtree/contrib/mtree/verify.c
Modified: projects/mtree/contrib/mtree/Makefile
==============================================================================
--- projects/mtree/contrib/mtree/Makefile Fri Sep 21 19:22:43 2012 (r240785)
+++ projects/mtree/contrib/mtree/Makefile Fri Sep 21 19:26:21 2012 (r240786)
@@ -7,7 +7,8 @@ PROG= mtree
#CPPFLAGS+=-DDEBUG
CPPFLAGS+= -DMTREE
MAN= mtree.8
-SRCS= compare.c crc.c create.c excludes.c misc.c mtree.c spec.c verify.c \
+SRCS= compare.c crc.c create.c excludes.c misc.c mtree.c spec.c specspec.c \
+ verify.c \
getid.c pack_dev.c
.if (${HOSTPROG:U} == "")
DPADD+= ${LIBUTIL}
Modified: projects/mtree/contrib/mtree/extern.h
==============================================================================
--- projects/mtree/contrib/mtree/extern.h Fri Sep 21 19:22:43 2012 (r240785)
+++ projects/mtree/contrib/mtree/extern.h Fri Sep 21 19:26:21 2012 (r240786)
@@ -67,7 +67,7 @@ void parsetags(slist_t *, char *);
u_int parsetype(const char *);
void read_excludes_file(const char *);
const char *rlink(const char *);
-int verify(void);
+int verify(FILE *);
extern int dflag, eflag, iflag, jflag, lflag, mflag,
nflag, qflag, rflag, sflag, tflag, uflag;
Modified: projects/mtree/contrib/mtree/mtree.c
==============================================================================
--- projects/mtree/contrib/mtree/mtree.c Fri Sep 21 19:22:43 2012 (r240785)
+++ projects/mtree/contrib/mtree/mtree.c Fri Sep 21 19:26:21 2012 (r240786)
@@ -70,11 +70,14 @@ main(int argc, char **argv)
{
int ch, status;
char *dir, *p;
+ FILE *spec1, *spec2;
setprogname(argv[0]);
dir = NULL;
init_excludes();
+ spec1 = stdin;
+ spec2 = NULL;
while ((ch = getopt(argc, argv,
"cCdDeE:f:I:ijk:K:lLmMnN:p:PqrR:s:StuUwWxX:"))
@@ -99,8 +102,18 @@ main(int argc, char **argv)
eflag = 1;
break;
case 'f':
- if (!(freopen(optarg, "r", stdin)))
- mtree_err("%s: %s", optarg, strerror(errno));
+ if (spec1 == stdin) {
+ spec1 = fopen(optarg, "r");
+ if (spec1 == NULL)
+ mtree_err("%s: %s", optarg,
+ strerror(errno));
+ } else if (spec2 == NULL) {
+ spec2 = fopen(optarg, "r");
+ if (spec2 == NULL)
+ mtree_err("%s: %s", optarg,
+ strerror(errno));
+ } else
+ usage();
break;
case 'i':
iflag = 1;
@@ -223,10 +236,13 @@ main(int argc, char **argv)
exit(0);
}
if (Cflag || Dflag) {
- dump_nodes("", spec(stdin), Dflag);
+ dump_nodes("", spec(spec1), Dflag);
exit(0);
}
- status = verify();
+ if (spec2 != NULL)
+ status = mtree_specspec(spec1, spec2);
+ else
+ status = verify(spec1);
if (Uflag && (status == MISMATCHEXIT))
status = 0;
exit(status);
@@ -237,7 +253,8 @@ usage(void)
{
fprintf(stderr,
- "usage: %s [-CcDdeLlMnPrSUuWx] [-i|-m] [-E tags] [-f spec]\n"
+ "usage: %s [-CcDdeLlMnPrSUuWx] [-i|-m] [-E tags]\n"
+ "\t\t[-f spec] [-f spec]\n"
"\t\t[-I tags] [-K keywords] [-k keywords] [-N dbdir] [-p path]\n"
"\t\t[-R keywords] [-s seed] [-X exclude-file]\n",
getprogname());
Modified: projects/mtree/contrib/mtree/mtree.h
==============================================================================
--- projects/mtree/contrib/mtree/mtree.h Fri Sep 21 19:22:43 2012 (r240785)
+++ projects/mtree/contrib/mtree/mtree.h Fri Sep 21 19:26:21 2012 (r240786)
@@ -120,6 +120,7 @@ const char *inotype(u_int);
u_int nodetoino(u_int);
int setup_getid(const char *);
NODE *spec(FILE *);
+int mtree_specspec(FILE *, FILE *);
void free_nodes(NODE *);
char *vispath(const char *);
Copied and modified: projects/mtree/contrib/mtree/specspec.c (from r240785, projects/mtree/usr.sbin/mtree/specspec.c)
==============================================================================
--- projects/mtree/usr.sbin/mtree/specspec.c Fri Sep 21 19:22:43 2012 (r240785, copy source)
+++ projects/mtree/contrib/mtree/specspec.c Fri Sep 21 19:26:21 2012 (r240786)
@@ -32,6 +32,8 @@ __FBSDID("$FreeBSD$");
#include <pwd.h>
#include <stdio.h>
#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include "mtree.h"
#include "extern.h"
@@ -49,7 +51,7 @@ shownode(NODE *n, int f, char const *pat
struct group *gr;
struct passwd *pw;
- printf("%s%s %s", path, n->name, ftype(n->type));
+ printf("%s%s %s", path, n->name, inotype(nodetoino(n->type)));
if (f & F_CKSUM)
printf(" cksum=%lu", n->cksum);
if (f & F_GID)
@@ -85,7 +87,7 @@ shownode(NODE *n, int f, char const *pat
if (f & F_SHA256)
printf(" sha256digest=%s", n->sha256digest);
if (f & F_FLAGS)
- printf(" flags=%s", flags_to_string(n->st_flags));
+ printf(" flags=%s", flags_to_string(n->st_flags, "none"));
printf("\n");
}
@@ -246,8 +248,8 @@ mtree_specspec(FILE *fi, FILE *fj)
int rval;
NODE *root1, *root2;
- root1 = mtree_readspec(fi);
- root2 = mtree_readspec(fj);
+ root1 = spec(fi);
+ root2 = spec(fj);
rval = walk_in_the_forest(root1, root2, "");
rval += compare_nodes(root1, root2, "");
if (rval > 0)
Modified: projects/mtree/contrib/mtree/verify.c
==============================================================================
--- projects/mtree/contrib/mtree/verify.c Fri Sep 21 19:22:43 2012 (r240785)
+++ projects/mtree/contrib/mtree/verify.c Fri Sep 21 19:26:21 2012 (r240786)
@@ -64,11 +64,11 @@ static void miss(NODE *, char *);
static int vwalk(void);
int
-verify(void)
+verify(FILE *fi)
{
int rval;
- root = spec(stdin);
+ root = spec(fi);
rval = vwalk();
miss(root, path);
return (rval);
More information about the svn-src-projects
mailing list