]>
git.saurik.com Git - apple/file_cmds.git/blob - mtree/specspec.c
113d2fdc3c3d993f4498df742c6a1f29adfdf123
2 * Copyright (c) 2003 Poul-Henning Kamp
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD: src/usr.sbin/mtree/specspec.c,v 1.6 2005/03/29 11:44:17 tobez Exp $");
30 #include <sys/param.h>
40 #define FF(a, b, c, d) \
41 (((a)->flags & (c)) && ((b)->flags & (c)) && ((a)->d) != ((b)->d))
42 #define FS(a, b, c, d) \
43 (((a)->flags & (c)) && ((b)->flags & (c)) && strcmp((a)->d,(b)->d))
44 #define FM(a, b, c, d) \
45 (((a)->flags & (c)) && ((b)->flags & (c)) && memcmp(&(a)->d,&(b)->d, sizeof (a)->d))
48 shownode(NODE
*n
, int f
, char const *path
)
53 printf("%s%s %s", path
, n
->name
, ftype(n
->type
));
55 printf(" cksum=%lu", n
->cksum
);
57 printf(" gid=%d", n
->st_gid
);
59 gr
= getgrgid(n
->st_gid
);
61 printf(" gid=%d", n
->st_gid
);
63 printf(" gname=%s", gr
->gr_name
);
66 printf(" mode=%o", n
->st_mode
);
68 printf(" nlink=%d", n
->st_nlink
);
70 printf(" size=%jd", (intmax_t)n
->st_size
);
72 printf(" uid=%d", n
->st_uid
);
74 pw
= getpwuid(n
->st_uid
);
76 printf(" uid=%d", n
->st_uid
);
78 printf(" uname=%s", pw
->pw_name
);
81 printf(" md5digest=%s", n
->md5digest
);
83 printf(" sha1digest=%s", n
->sha1digest
);
85 printf(" rmd160digest=%s", n
->rmd160digest
);
87 printf(" sha256digest=%s", n
->sha256digest
);
89 printf(" flags=%s", flags_to_string(n
->st_flags
));
94 mismatch(NODE
*n1
, NODE
*n2
, int differ
, char const *path
)
98 shownode(n1
, differ
, path
);
103 shownode(n2
, differ
, path
);
106 if (!(differ
& keys
))
109 shownode(n1
, differ
, path
);
111 shownode(n2
, differ
, path
);
116 compare_nodes(NODE
*n1
, NODE
*n2
, char const *path
)
120 if (n1
!= NULL
&& n1
->type
== F_LINK
)
121 n1
->flags
&= ~F_MODE
;
122 if (n2
!= NULL
&& n2
->type
== F_LINK
)
123 n2
->flags
&= ~F_MODE
;
125 if ((n1
== NULL
) && (n2
== NULL
)) {
127 } else if (n1
== NULL
) {
129 mismatch(n1
, n2
, differs
, path
);
131 } else if (n2
== NULL
) {
133 mismatch(n1
, n2
, differs
, path
);
135 } else if (n1
->type
!= n2
->type
) {
137 mismatch(n1
, n2
, differs
, path
);
140 if (FF(n1
, n2
, F_CKSUM
, cksum
))
142 if (FF(n1
, n2
, F_GID
, st_gid
))
144 if (FF(n1
, n2
, F_GNAME
, st_gid
))
146 if (FF(n1
, n2
, F_MODE
, st_mode
))
148 if (FF(n1
, n2
, F_NLINK
, st_nlink
))
150 if (FF(n1
, n2
, F_SIZE
, st_size
))
152 if (FS(n1
, n2
, F_SLINK
, slink
))
154 if (FM(n1
, n2
, F_TIME
, st_mtimespec
))
156 if (FF(n1
, n2
, F_UID
, st_uid
))
158 if (FF(n1
, n2
, F_UNAME
, st_uid
))
160 if (FS(n1
, n2
, F_MD5
, md5digest
))
162 if (FS(n1
, n2
, F_SHA1
, sha1digest
))
164 if (FS(n1
, n2
, F_RMD160
, rmd160digest
))
166 if (FS(n1
, n2
, F_SHA256
, sha256digest
))
168 if (FF(n1
, n2
, F_FLAGS
, st_flags
))
171 mismatch(n1
, n2
, differs
, path
);
177 walk_in_the_forest(NODE
*t1
, NODE
*t2
, char const *path
)
180 NODE
*c1
, *c2
, *n1
, *n2
;
193 while (c1
!= NULL
|| c2
!= NULL
) {
199 if (c1
!= NULL
&& c2
!= NULL
) {
200 if (c1
->type
!= F_DIR
&& c2
->type
== F_DIR
) {
203 } else if (c1
->type
== F_DIR
&& c2
->type
!= F_DIR
) {
207 i
= strcmp(c1
->name
, c2
->name
);
217 if (c1
== NULL
&& c2
->type
== F_DIR
) {
218 asprintf(&np
, "%s%s/", path
, c2
->name
);
219 i
= walk_in_the_forest(c1
, c2
, np
);
221 i
+= compare_nodes(c1
, c2
, path
);
222 } else if (c2
== NULL
&& c1
->type
== F_DIR
) {
223 asprintf(&np
, "%s%s/", path
, c1
->name
);
224 i
= walk_in_the_forest(c1
, c2
, np
);
226 i
+= compare_nodes(c1
, c2
, path
);
227 } else if (c1
== NULL
|| c2
== NULL
) {
228 i
= compare_nodes(c1
, c2
, path
);
229 } else if (c1
->type
== F_DIR
&& c2
->type
== F_DIR
) {
230 asprintf(&np
, "%s%s/", path
, c1
->name
);
231 i
= walk_in_the_forest(c1
, c2
, np
);
233 i
+= compare_nodes(c1
, c2
, path
);
235 i
= compare_nodes(c1
, c2
, path
);
245 mtree_specspec(FILE *fi
, FILE *fj
)
250 root1
= mtree_readspec(fi
);
251 root2
= mtree_readspec(fj
);
252 rval
= walk_in_the_forest(root1
, root2
, "");
253 rval
+= compare_nodes(root1
, root2
, "");
255 return (MISMATCHEXIT
);