summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mtree
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2000-10-03 13:13:47 +0000
committerphk <phk@FreeBSD.org>2000-10-03 13:13:47 +0000
commit42e3d092baad7027558e9c9e4861920f6a488df8 (patch)
tree5084beef4b37a04950da07aaa79f34314d3bd5ed /usr.sbin/mtree
parent98f1b14abae6bcc470fa2be3a0284923272e0b5a (diff)
downloadFreeBSD-src-42e3d092baad7027558e9c9e4861920f6a488df8.zip
FreeBSD-src-42e3d092baad7027558e9c9e4861920f6a488df8.tar.gz
Make the output of mtree(8) more systematic and machine readable.
The new format is: filename {changed,missing,extra} $field expected $foo found $bar ... Fix various bugs along the way: Don't complain about directory sizes differing. Correctly check flags.
Diffstat (limited to 'usr.sbin/mtree')
-rw-r--r--usr.sbin/mtree/compare.c78
-rw-r--r--usr.sbin/mtree/create.c12
-rw-r--r--usr.sbin/mtree/verify.c4
3 files changed, 46 insertions, 48 deletions
diff --git a/usr.sbin/mtree/compare.c b/usr.sbin/mtree/compare.c
index 3c6f015..b12f3fa 100644
--- a/usr.sbin/mtree/compare.c
+++ b/usr.sbin/mtree/compare.c
@@ -68,14 +68,8 @@ static char *ftype __P((u_int));
#define INDENTNAMELEN 8
#define LABEL \
if (!label++) { \
- len = printf("%s: ", RP(p)); \
- if (len > INDENTNAMELEN) { \
- tab = "\t"; \
- (void)printf("\n"); \
- } else { \
- tab = ""; \
- (void)printf("%*s", INDENTNAMELEN - (int)len, ""); \
- } \
+ len = printf("%s changed\n", RP(p)); \
+ tab = "\t"; \
}
int
@@ -119,7 +113,7 @@ compare(name, s, p)
case F_SOCK:
if (!S_ISSOCK(p->fts_statp->st_mode)) {
typeerr: LABEL;
- (void)printf("\ttype (%s, %s)\n",
+ (void)printf("\ttype expected %s found %s\n",
ftype(s->type), inotype(p->fts_statp->st_mode));
}
break;
@@ -127,57 +121,58 @@ typeerr: LABEL;
/* Set the uid/gid first, then set the mode. */
if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) {
LABEL;
- (void)printf("%suser (%lu, %lu",
+ (void)printf("%suser expected %lu found %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))
- (void)printf(", not modified: %s)\n",
+ (void)printf(" not modified: %s\n",
strerror(errno));
else
- (void)printf(", modified)\n");
+ (void)printf(" modified\n");
else
- (void)printf(")\n");
+ (void)printf("\n");
tab = "\t";
}
if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) {
LABEL;
- (void)printf("%sgid (%lu, %lu",
+ (void)printf("%sgid expected %lu found %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))
- (void)printf(", not modified: %s)\n",
+ (void)printf(" not modified: %s\n",
strerror(errno));
else
- (void)printf(", modified)\n");
+ (void)printf(" modified\n");
else
- (void)printf(")\n");
+ (void)printf("\n");
tab = "\t";
}
if (s->flags & F_MODE &&
s->st_mode != (p->fts_statp->st_mode & MBITS)) {
LABEL;
- (void)printf("%spermissions (%#o, %#o",
+ (void)printf("%spermissions expected %#o found %#o",
tab, s->st_mode, p->fts_statp->st_mode & MBITS);
if (uflag)
if (chmod(p->fts_accpath, s->st_mode))
- (void)printf(", not modified: %s)\n",
+ (void)printf(" not modified: %s\n",
strerror(errno));
else
- (void)printf(", modified)\n");
+ (void)printf(" modified\n");
else
- (void)printf(")\n");
+ (void)printf("\n");
tab = "\t";
}
if (s->flags & F_NLINK && s->type != F_DIR &&
s->st_nlink != p->fts_statp->st_nlink) {
LABEL;
- (void)printf("%slink count (%u, %u)\n",
+ (void)printf("%slink_count expected %u found %u\n",
tab, s->st_nlink, p->fts_statp->st_nlink);
tab = "\t";
}
- if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) {
+ if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size &&
+ !S_ISDIR(p->fts_statp->st_mode)) {
LABEL;
- (void)printf("%ssize (%qd, %qd)\n",
+ (void)printf("%ssize expected %qd found %qd\n",
tab, s->st_size, p->fts_statp->st_size);
tab = "\t";
}
@@ -189,9 +184,9 @@ typeerr: LABEL;
((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, ",
+ (void)printf("%smodification time expected %.24s ",
tab, ctime(&s->st_mtimespec.tv_sec));
- (void)printf("%.24s)\n",
+ (void)printf("found %.24s\n",
ctime(&p->fts_statp->st_mtimespec.tv_sec));
tab = "\t";
}
@@ -211,7 +206,7 @@ typeerr: LABEL;
(void)close(fd);
if (s->cksum != val) {
LABEL;
- (void)printf("%scksum (%lu, %lu)\n",
+ (void)printf("%scksum expected %lu found %lu\n",
tab, s->cksum, val);
}
tab = "\t";
@@ -226,21 +221,21 @@ typeerr: LABEL;
if ((s->flags & F_FLAGS) && s->st_flags != p->fts_statp->st_flags) {
LABEL;
fflags = flags_to_string(s->st_flags);
- (void)printf("%sflags (\"%s\" is not ", tab, fflags);
+ (void)printf("%sflags expected \"%s\"", tab, fflags);
free(fflags);
fflags = flags_to_string(p->fts_statp->st_flags);
- (void)printf("\"%s\"", fflags);
+ (void)printf(" found \"%s\"", fflags);
free(fflags);
if (uflag)
if (chflags(p->fts_accpath, s->st_flags))
- (void)printf(", not modified: %s)\n",
+ (void)printf(" not modified: %s\n",
strerror(errno));
else
- (void)printf(", modified)\n");
+ (void)printf(" modified\n");
else
- (void)printf(")\n");
+ (void)printf("\n");
tab = "\t";
}
#ifdef MD5
@@ -250,12 +245,12 @@ typeerr: LABEL;
new_digest = MD5File(p->fts_accpath, buf);
if (!new_digest) {
LABEL;
- printf("%sMD5File: %s: %s\n", tab, p->fts_accpath,
+ printf("%sMD5: %s: %s\n", tab, p->fts_accpath,
strerror(errno));
tab = "\t";
} else if (strcmp(new_digest, s->md5digest)) {
LABEL;
- printf("%sMD5 (%s, %s)\n", tab, s->md5digest,
+ printf("%sMD5 expected %s found %s\n", tab, s->md5digest,
new_digest);
tab = "\t";
}
@@ -268,13 +263,13 @@ typeerr: LABEL;
new_digest = SHA1_File(p->fts_accpath, buf);
if (!new_digest) {
LABEL;
- printf("%sSHA1_File: %s: %s\n", tab, p->fts_accpath,
+ printf("%sSHA-1: %s: %s\n", tab, p->fts_accpath,
strerror(errno));
tab = "\t";
} else if (strcmp(new_digest, s->sha1digest)) {
LABEL;
- printf("%sSHA-1 (%s, %s)\n", tab, s->sha1digest,
- new_digest);
+ printf("%sSHA-1 expected %s found %s\n",
+ tab, s->sha1digest, new_digest);
tab = "\t";
}
}
@@ -286,13 +281,13 @@ typeerr: LABEL;
new_digest = RIPEMD160_File(p->fts_accpath, buf);
if (!new_digest) {
LABEL;
- printf("%sRIPEMD160_File: %s: %s\n", tab,
+ printf("%sRIPEMD160: %s: %s\n", tab,
p->fts_accpath, strerror(errno));
tab = "\t";
} else if (strcmp(new_digest, s->rmd160digest)) {
LABEL;
- printf("%sRIPEMD160 (%s, %s)\n", tab, s->rmd160digest,
- new_digest);
+ printf("%sRIPEMD160 expected %s found %s\n",
+ tab, s->rmd160digest, new_digest);
tab = "\t";
}
}
@@ -301,7 +296,8 @@ typeerr: LABEL;
if (s->flags & F_SLINK &&
strcmp(cp = rlink(p->fts_accpath), s->slink)) {
LABEL;
- (void)printf("%slink ref (%s, %s)\n", tab, cp, s->slink);
+ (void)printf("%slink_ref expected %s found %s\n",
+ tab, cp, s->slink);
}
return (label);
}
diff --git a/usr.sbin/mtree/create.c b/usr.sbin/mtree/create.c
index 6a2d005..01f72c9 100644
--- a/usr.sbin/mtree/create.c
+++ b/usr.sbin/mtree/create.c
@@ -77,7 +77,7 @@ extern int lineno;
static gid_t gid;
static uid_t uid;
static mode_t mode;
-static u_long flags;
+static u_long flags = 0xffffffff;
static int dsort __P((const FTSENT **, const FTSENT **));
static void output __P((int, int *, const char *, ...));
@@ -290,7 +290,7 @@ statd(t, parent, puid, pgid, pmode, pflags)
gid_t savegid = *pgid;
uid_t saveuid = *puid;
mode_t savemode = *pmode;
- u_long saveflags = 0;
+ u_long saveflags = *pflags;
u_short maxgid, maxuid, maxmode, maxflags;
u_short g[MAXGID], u[MAXUID], m[MAXMODE], f[MAXFLAGS];
char *fflags;
@@ -337,7 +337,7 @@ statd(t, parent, puid, pgid, pmode, pflags)
if (FLAGS2IDX(sflags) < MAXFLAGS &&
++f[FLAGS2IDX(sflags)] > maxflags) {
saveflags = sflags;
- maxflags = u[FLAGS2IDX(sflags)];
+ maxflags = f[FLAGS2IDX(sflags)];
}
}
}
@@ -348,7 +348,9 @@ statd(t, parent, puid, pgid, pmode, pflags)
*/
if ((((keys & F_UNAME) | (keys & F_UID)) && (*puid != saveuid)) ||
(((keys & F_GNAME) | (keys & F_GID)) && (*pgid != savegid)) ||
- ((keys & F_MODE) && (*pmode != savemode)) || (first)) {
+ ((keys & F_MODE) && (*pmode != savemode)) ||
+ ((keys & F_FLAGS) && (*pflags != saveflags)) ||
+ (first)) {
first = 0;
if (dflag)
(void)printf("/set type=dir");
@@ -378,7 +380,7 @@ statd(t, parent, puid, pgid, pmode, pflags)
(void)printf(" mode=%#o", savemode);
if (keys & F_NLINK)
(void)printf(" nlink=1");
- if (keys & F_FLAGS && saveflags) {
+ if (keys & F_FLAGS) {
fflags = flags_to_string(saveflags);
(void)printf(" flags=%s", fflags);
free(fflags);
diff --git a/usr.sbin/mtree/verify.c b/usr.sbin/mtree/verify.c
index a599fad..0da0e12 100644
--- a/usr.sbin/mtree/verify.c
+++ b/usr.sbin/mtree/verify.c
@@ -139,7 +139,7 @@ vwalk()
continue;
extra:
if (!eflag) {
- (void)printf("extra: %s", RP(p));
+ (void)printf("%s extra", RP(p));
if (rflag) {
if ((S_ISDIR(p->fts_statp->st_mode)
? rmdir : unlink)(p->fts_accpath)) {
@@ -179,7 +179,7 @@ miss(p, tail)
if (qflag && stat(path, &statbuf) == 0)
p->flags |= F_VISIT;
else
- (void)printf("missing: %s", path);
+ (void)printf("%s missing", path);
}
if (p->type != F_DIR && p->type != F_LINK) {
putchar('\n');
OpenPOWER on IntegriCloud