]>
git.saurik.com Git - apple/file_cmds.git/blob - mtree/compare.c
596f9de2be6a1b81c864ada45f2ac4ffcdc8e19e
1 /* $NetBSD: compare.c,v 1.15 1998/08/27 18:03:45 ross Exp $ */
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)compare.c 8.1 (Berkeley) 6/6/93";
41 __RCSID("$NetBSD: compare.c,v 1.15 1998/08/27 18:03:45 ross Exp $");
45 #include <sys/param.h>
56 extern int tflag
, uflag
;
58 static char *ftype
__P((u_int
));
60 #define INDENTNAMELEN 8
63 len = printf("%s: ", RP(p)); \
64 if (len > INDENTNAMELEN) { \
69 (void)printf("%*s", INDENTNAMELEN - (int)len, ""); \
87 if (!S_ISBLK(p
->fts_statp
->st_mode
))
91 if (!S_ISCHR(p
->fts_statp
->st_mode
))
95 if (!S_ISDIR(p
->fts_statp
->st_mode
))
99 if (!S_ISFIFO(p
->fts_statp
->st_mode
))
103 if (!S_ISREG(p
->fts_statp
->st_mode
))
107 if (!S_ISLNK(p
->fts_statp
->st_mode
))
111 if (!S_ISSOCK(p
->fts_statp
->st_mode
)) {
113 (void)printf("\ttype (%s, %s)\n",
114 ftype(s
->type
), inotype(p
->fts_statp
->st_mode
));
118 /* Set the uid/gid first, then set the mode. */
119 if (s
->flags
& (F_UID
| F_UNAME
) && s
->st_uid
!= p
->fts_statp
->st_uid
) {
121 (void)printf("%suser (%u, %u",
122 tab
, s
->st_uid
, p
->fts_statp
->st_uid
);
124 if (chown(p
->fts_accpath
, s
->st_uid
, -1))
125 (void)printf(", not modified: %s)\n",
128 (void)printf(", modified)\n");
133 if (s
->flags
& (F_GID
| F_GNAME
) && s
->st_gid
!= p
->fts_statp
->st_gid
) {
135 (void)printf("%sgid (%u, %u",
136 tab
, s
->st_gid
, p
->fts_statp
->st_gid
);
138 if (chown(p
->fts_accpath
, -1, s
->st_gid
))
139 (void)printf(", not modified: %s)\n",
142 (void)printf(", modified)\n");
147 if (s
->flags
& F_MODE
&&
148 s
->st_mode
!= (p
->fts_statp
->st_mode
& MBITS
)) {
150 (void)printf("%spermissions (%#o, %#o",
151 tab
, s
->st_mode
, p
->fts_statp
->st_mode
& MBITS
);
153 if (chmod(p
->fts_accpath
, s
->st_mode
))
154 (void)printf(", not modified: %s)\n",
157 (void)printf(", modified)\n");
162 if (s
->flags
& F_NLINK
&& s
->type
!= F_DIR
&&
163 s
->st_nlink
!= p
->fts_statp
->st_nlink
) {
165 (void)printf("%slink count (%u, %u)\n",
166 tab
, s
->st_nlink
, p
->fts_statp
->st_nlink
);
169 if (s
->flags
& F_SIZE
&& s
->st_size
!= p
->fts_statp
->st_size
) {
171 (void)printf("%ssize (%qd, %qd)\n",
172 tab
, (long long)s
->st_size
,
173 (long long)p
->fts_statp
->st_size
);
178 * Since utimes(2) only takes a timeval, there's no point in
179 * comparing the low bits of the timespec nanosecond field. This
180 * will only result in mismatches that we can never fix.
182 * Doesn't display microsecond differences.
184 if (s
->flags
& F_TIME
) {
185 struct timeval tv
[2];
187 TIMESPEC_TO_TIMEVAL(&tv
[0], &s
->st_mtimespec
);
188 TIMESPEC_TO_TIMEVAL(&tv
[1], &p
->fts_statp
->st_mtimespec
);
189 if (tv
[0].tv_sec
!= tv
[1].tv_sec
||
190 tv
[0].tv_usec
!= tv
[1].tv_usec
) {
192 (void)printf("%smodification time (%.24s, ",
193 tab
, ctime(&s
->st_mtimespec
.tv_sec
));
194 (void)printf("%.24s",
195 ctime(&p
->fts_statp
->st_mtimespec
.tv_sec
));
198 if (utimes(p
->fts_accpath
, tv
))
199 (void)printf(", not modified: %s)\n",
202 (void)printf(", modified)\n");
208 if (s
->flags
& F_CKSUM
) {
209 if ((fd
= open(p
->fts_accpath
, O_RDONLY
, 0)) < 0) {
211 (void)printf("%scksum: %s: %s\n",
212 tab
, p
->fts_accpath
, strerror(errno
));
214 } else if (crc(fd
, &val
, &len
)) {
217 (void)printf("%scksum: %s: %s\n",
218 tab
, p
->fts_accpath
, strerror(errno
));
222 if (s
->cksum
!= val
) {
224 (void)printf("%scksum (%lu, %lu)\n",
225 tab
, s
->cksum
, (unsigned long)val
);
230 if (s
->flags
& F_SLINK
&& strcmp(cp
= rlink(name
), s
->slink
)) {
232 (void)printf("%slink ref (%s, %s)\n", tab
, cp
, s
->slink
);
241 switch(type
& S_IFMT
) {
291 static char lbuf
[MAXPATHLEN
];
294 if ((len
= readlink(name
, lbuf
, sizeof(lbuf
))) == -1)
295 mtree_err("%s: %s", name
, strerror(errno
));