1996-05-09 20:54:06 +00:00
|
|
|
/* Still missing:
|
|
|
|
*
|
|
|
|
* mkctm
|
|
|
|
* -B regex Bogus
|
|
|
|
* -I regex Ignore
|
1996-05-14 07:25:59 +00:00
|
|
|
* -D int Damage
|
|
|
|
* -q decrease verbosity
|
1996-05-09 20:54:06 +00:00
|
|
|
* -v increase verbosity
|
1996-11-16 19:30:14 +00:00
|
|
|
* -l file logfile
|
1996-05-09 20:54:06 +00:00
|
|
|
* name cvs-cur
|
|
|
|
* prefix src/secure
|
|
|
|
* dir1 "Soll"
|
|
|
|
* dir2 "Ist"
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <md5.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
1996-05-14 07:25:59 +00:00
|
|
|
#define DEFAULT_IGNORE "/CVS$|/\\.#|00_TRANS\\.TBL$"
|
1996-11-16 19:30:14 +00:00
|
|
|
#define DEFAULT_BOGUS "\\.core$|\\.orig$|\\.rej$|\\.o$"
|
1996-05-09 20:54:06 +00:00
|
|
|
regex_t reg_ignore, reg_bogus;
|
|
|
|
int flag_ignore, flag_bogus;
|
|
|
|
|
1996-05-14 07:25:59 +00:00
|
|
|
int verbose;
|
|
|
|
int damage, damage_limit;
|
|
|
|
int change;
|
|
|
|
|
1996-11-16 19:30:14 +00:00
|
|
|
FILE *logf;
|
|
|
|
|
1996-05-09 20:54:06 +00:00
|
|
|
u_long s1_ignored, s2_ignored;
|
|
|
|
u_long s1_bogus, s2_bogus;
|
|
|
|
u_long s1_wrong, s2_wrong;
|
|
|
|
u_long s_new_dirs, s_new_files, s_new_bytes;
|
1996-05-14 07:25:59 +00:00
|
|
|
u_long s_del_dirs, s_del_files, s_del_bytes;
|
|
|
|
u_long s_files_chg, s_bytes_add, s_bytes_del;
|
|
|
|
u_long s_same_dirs, s_same_files, s_same_bytes;
|
1996-05-09 20:54:06 +00:00
|
|
|
u_long s_edit_files, s_edit_bytes, s_edit_saves;
|
|
|
|
u_long s_sub_files, s_sub_bytes;
|
|
|
|
|
1996-05-14 07:25:59 +00:00
|
|
|
void
|
|
|
|
Usage(void)
|
|
|
|
{
|
1997-09-17 06:24:58 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"usage: mkctm [-options] name number timestamp prefix dir1 dir2\n");
|
|
|
|
fprintf(stderr, "options:\n");
|
1996-05-14 07:25:59 +00:00
|
|
|
fprintf(stderr, "\t\t-B bogus_regexp\n");
|
|
|
|
fprintf(stderr, "\t\t-D damage_limit\n");
|
|
|
|
fprintf(stderr, "\t\t-I ignore_regexp\n");
|
|
|
|
fprintf(stderr, "\t\t-q\n");
|
|
|
|
fprintf(stderr, "\t\t-v\n");
|
|
|
|
}
|
|
|
|
|
1996-05-09 20:54:06 +00:00
|
|
|
void
|
|
|
|
print_stat(FILE *fd, char *pre)
|
|
|
|
{
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(fd, "%sNames:\n", pre);
|
|
|
|
fprintf(fd, "%s ignore: %5lu ref %5lu target\n",
|
1996-05-09 20:54:06 +00:00
|
|
|
pre, s1_ignored, s2_ignored);
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(fd, "%s bogus: %5lu ref %5lu target\n",
|
1996-05-09 20:54:06 +00:00
|
|
|
pre, s1_bogus, s2_bogus);
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(fd, "%s wrong: %5lu ref %5lu target\n",
|
1996-05-09 20:54:06 +00:00
|
|
|
pre, s1_wrong, s2_wrong);
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(fd, "%sDelta:\n", pre);
|
|
|
|
fprintf(fd, "%s new: %5lu dirs %5lu files %9lu plus\n",
|
1996-05-09 20:54:06 +00:00
|
|
|
pre, s_new_dirs, s_new_files, s_new_bytes);
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(fd, "%s del: %5lu dirs %5lu files %9lu minus\n",
|
1996-05-09 20:54:06 +00:00
|
|
|
pre, s_del_dirs, s_del_files, s_del_bytes);
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(fd, "%s chg: %5lu files %9lu plus %9lu minus\n",
|
1996-05-09 20:54:06 +00:00
|
|
|
pre, s_files_chg, s_bytes_add, s_bytes_del);
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(fd, "%s same: %5lu dirs %5lu files %9lu bytes\n",
|
1996-05-09 20:54:06 +00:00
|
|
|
pre, s_same_dirs, s_same_files, s_same_bytes);
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(fd, "%sMethod:\n", pre);
|
|
|
|
fprintf(fd, "%s edit: %5lu files %9lu bytes %9lu saved\n",
|
1996-05-09 20:54:06 +00:00
|
|
|
pre, s_edit_files, s_edit_bytes, s_edit_saves);
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(fd, "%s sub: %5lu files %9lu bytes\n",
|
1996-05-09 20:54:06 +00:00
|
|
|
pre, s_sub_files, s_sub_bytes);
|
1996-11-16 19:30:14 +00:00
|
|
|
|
1996-05-09 20:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
stat_info(int foo)
|
|
|
|
{
|
1996-11-16 19:30:14 +00:00
|
|
|
signal(SIGINFO, stat_info);
|
|
|
|
print_stat(stderr, "INFO: ");
|
1996-05-09 20:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DoDir(const char *dir1, const char *dir2, const char *name);
|
|
|
|
|
|
|
|
static struct stat st;
|
|
|
|
static __inline struct stat *
|
|
|
|
StatFile(char *name)
|
|
|
|
{
|
1996-11-16 19:30:14 +00:00
|
|
|
if (lstat(name, &st) < 0)
|
1997-09-17 06:24:58 +00:00
|
|
|
err(1, "couldn't stat %s", name);
|
1996-05-09 20:54:06 +00:00
|
|
|
return &st;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dirselect(struct dirent *de)
|
|
|
|
{
|
1996-11-16 19:30:14 +00:00
|
|
|
if (!strcmp(de->d_name, ".")) return 0;
|
|
|
|
if (!strcmp(de->d_name, "..")) return 0;
|
1996-05-09 20:54:06 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
name_stat(const char *pfx, const char *dir, const char *name, struct dirent *de)
|
|
|
|
{
|
|
|
|
char *buf = alloca(strlen(dir) + strlen(name) +
|
|
|
|
strlen(de->d_name) + 3);
|
|
|
|
struct stat *st;
|
|
|
|
|
1996-11-16 19:30:14 +00:00
|
|
|
strcpy(buf, dir);
|
|
|
|
strcat(buf, "/"); strcat(buf, name);
|
|
|
|
strcat(buf, "/"); strcat(buf, de->d_name);
|
1996-05-09 20:54:06 +00:00
|
|
|
st = StatFile(buf);
|
1996-11-16 19:30:14 +00:00
|
|
|
printf("%s %s%s %u %u %o",
|
1996-05-09 20:54:06 +00:00
|
|
|
pfx, name, de->d_name,
|
|
|
|
st->st_uid, st->st_gid, st->st_mode & ~S_IFMT);
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(logf, "%s %s%s\n", pfx, name, de->d_name);
|
1996-05-14 07:25:59 +00:00
|
|
|
if (verbose > 1) {
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(stderr, "%s %s%s\n", pfx, name, de->d_name);
|
1996-05-14 07:25:59 +00:00
|
|
|
}
|
1996-05-09 20:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Equ(const char *dir1, const char *dir2, const char *name, struct dirent *de)
|
|
|
|
{
|
|
|
|
if (de->d_type == DT_DIR) {
|
|
|
|
char *p = alloca(strlen(name)+strlen(de->d_name)+2);
|
|
|
|
|
1996-11-16 19:30:14 +00:00
|
|
|
strcpy(p, name); strcat(p, de->d_name); strcat(p, "/");
|
|
|
|
DoDir(dir1, dir2, p);
|
1996-05-09 20:54:06 +00:00
|
|
|
s_same_dirs++;
|
|
|
|
} else {
|
|
|
|
char *buf1 = alloca(strlen(dir1) + strlen(name) +
|
|
|
|
strlen(de->d_name) + 3);
|
|
|
|
char *buf2 = alloca(strlen(dir2) + strlen(name) +
|
|
|
|
strlen(de->d_name) + 3);
|
1996-11-16 19:30:14 +00:00
|
|
|
char *m1, md5_1[33], *m2, md5_2[33];
|
|
|
|
u_char *p1, *p2;
|
|
|
|
int fd1, fd2;
|
|
|
|
struct stat s1, s2;
|
|
|
|
|
|
|
|
strcpy(buf1, dir1);
|
|
|
|
strcat(buf1, "/"); strcat(buf1, name);
|
|
|
|
strcat(buf1, "/"); strcat(buf1, de->d_name);
|
|
|
|
fd1 = open(buf1, O_RDONLY);
|
1997-09-17 06:24:58 +00:00
|
|
|
if(fd1 < 0) { err(3, "%s", buf1); }
|
1996-11-16 19:30:14 +00:00
|
|
|
fstat(fd1, &s1);
|
|
|
|
strcpy(buf2, dir2);
|
|
|
|
strcat(buf2, "/"); strcat(buf2, name);
|
|
|
|
strcat(buf2, "/"); strcat(buf2, de->d_name);
|
|
|
|
fd2 = open(buf2, O_RDONLY);
|
1997-09-17 06:24:58 +00:00
|
|
|
if(fd2 < 0) { err(3, "%s", buf2); }
|
1996-11-16 19:30:14 +00:00
|
|
|
fstat(fd2, &s2);
|
1996-05-14 07:25:59 +00:00
|
|
|
#if 0
|
|
|
|
/* XXX if we could just trust the size to change... */
|
1996-05-09 20:54:06 +00:00
|
|
|
if (s1.st_size == s2.st_size) {
|
|
|
|
s_same_files++;
|
|
|
|
s_same_bytes += s1.st_size;
|
|
|
|
close(fd1);
|
|
|
|
close(fd2);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
#endif
|
1996-11-16 19:30:14 +00:00
|
|
|
p1=mmap(0, s1.st_size, PROT_READ, MAP_PRIVATE, fd1, 0);
|
1997-09-17 06:24:58 +00:00
|
|
|
if (p1 == (u_char *)MAP_FAILED) { err(3, "%s", buf1); }
|
1996-05-09 20:54:06 +00:00
|
|
|
close(fd1);
|
|
|
|
|
1996-11-16 19:30:14 +00:00
|
|
|
p2=mmap(0, s2.st_size, PROT_READ, MAP_PRIVATE, fd2, 0);
|
1997-09-17 06:24:58 +00:00
|
|
|
if (p2 == (u_char *)MAP_FAILED) { err(3, "%s", buf2); }
|
1996-05-09 20:54:06 +00:00
|
|
|
close(fd2);
|
|
|
|
|
|
|
|
/* If identical, we're done. */
|
1996-11-16 19:30:14 +00:00
|
|
|
if((s1.st_size == s2.st_size) && !memcmp(p1, p2, s1.st_size)) {
|
1996-05-09 20:54:06 +00:00
|
|
|
s_same_files++;
|
|
|
|
s_same_bytes += s1.st_size;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_files_chg++;
|
1996-05-14 07:25:59 +00:00
|
|
|
change++;
|
1996-05-09 20:54:06 +00:00
|
|
|
if (s1.st_size > s2.st_size)
|
|
|
|
s_bytes_del += (s1.st_size - s2.st_size);
|
|
|
|
else
|
|
|
|
s_bytes_add += (s2.st_size - s1.st_size);
|
|
|
|
|
|
|
|
m1 = MD5Data(p1, s1.st_size, md5_1);
|
|
|
|
m2 = MD5Data(p2, s2.st_size, md5_2);
|
|
|
|
|
|
|
|
/* Just a curiosity... */
|
1996-11-16 19:30:14 +00:00
|
|
|
if(!strcmp(m1, m2)) {
|
1996-05-09 20:54:06 +00:00
|
|
|
if (s1.st_size != s2.st_size)
|
|
|
|
fprintf(stderr,
|
|
|
|
"Notice: MD5 same for files of diffent size:\n\t%s\n\t%s\n",
|
1996-11-16 19:30:14 +00:00
|
|
|
buf1, buf2);
|
1996-05-09 20:54:06 +00:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
1996-05-14 07:25:59 +00:00
|
|
|
u_long l = s2.st_size + 2;
|
|
|
|
u_char *cmd = alloca(strlen(buf1)+strlen(buf2)+100);
|
|
|
|
u_char *ob = alloca(l), *p;
|
|
|
|
int j;
|
|
|
|
FILE *F;
|
|
|
|
|
1996-11-21 15:17:04 +00:00
|
|
|
if (s1.st_size && p1[s1.st_size-1] != '\n') {
|
1996-05-14 07:25:59 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
fprintf(stderr,
|
|
|
|
"last char != \\n in %s\n",
|
|
|
|
buf1);
|
|
|
|
goto subst;
|
|
|
|
}
|
|
|
|
|
1996-11-21 15:17:04 +00:00
|
|
|
if (s2.st_size && p2[s2.st_size-1] != '\n') {
|
1996-05-14 07:25:59 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
fprintf(stderr,
|
|
|
|
"last char != \\n in %s\n",
|
|
|
|
buf2);
|
|
|
|
goto subst;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (p=p1; p<p1+s1.st_size; p++)
|
|
|
|
if (!*p) {
|
|
|
|
if (verbose > 0)
|
|
|
|
fprintf(stderr,
|
|
|
|
"NULL char in %s\n",
|
|
|
|
buf1);
|
|
|
|
goto subst;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (p=p2; p<p2+s2.st_size; p++)
|
|
|
|
if (!*p) {
|
|
|
|
if (verbose > 0)
|
|
|
|
fprintf(stderr,
|
|
|
|
"NULL char in %s\n",
|
|
|
|
buf2);
|
|
|
|
goto subst;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy(cmd, "diff -n ");
|
|
|
|
strcat(cmd, buf1);
|
|
|
|
strcat(cmd, " ");
|
|
|
|
strcat(cmd, buf2);
|
1996-11-16 19:30:14 +00:00
|
|
|
F = popen(cmd, "r");
|
1996-05-14 07:25:59 +00:00
|
|
|
for (j = 1, l = 0; l < s2.st_size; ) {
|
|
|
|
j = fread(ob+l, 1, s2.st_size - l, F);
|
|
|
|
if (j < 1)
|
|
|
|
break;
|
|
|
|
l += j;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (j) {
|
|
|
|
l = 0;
|
|
|
|
while (EOF != fgetc(F))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pclose(F);
|
|
|
|
|
1996-05-09 20:54:06 +00:00
|
|
|
if (l && l < s2.st_size) {
|
1996-11-16 19:30:14 +00:00
|
|
|
name_stat("CTMFN", dir2, name, de);
|
|
|
|
printf(" %s %s %d\n", m1, m2, (unsigned)l);
|
|
|
|
fwrite(ob, 1, l, stdout);
|
1996-05-14 07:25:59 +00:00
|
|
|
putchar('\n');
|
1996-05-09 20:54:06 +00:00
|
|
|
s_edit_files++;
|
|
|
|
s_edit_bytes += l;
|
|
|
|
s_edit_saves += (s2.st_size - l);
|
|
|
|
} else {
|
1996-05-14 07:25:59 +00:00
|
|
|
subst:
|
1996-11-16 19:30:14 +00:00
|
|
|
name_stat("CTMFS", dir2, name, de);
|
|
|
|
printf(" %s %s %u\n", m1, m2, (unsigned)s2.st_size);
|
|
|
|
fwrite(p2, 1, s2.st_size, stdout);
|
1996-05-14 07:25:59 +00:00
|
|
|
putchar('\n');
|
1996-05-09 20:54:06 +00:00
|
|
|
s_sub_files++;
|
|
|
|
s_sub_bytes += s2.st_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finish:
|
1996-11-16 19:30:14 +00:00
|
|
|
munmap(p1, s1.st_size);
|
|
|
|
munmap(p2, s2.st_size);
|
1996-05-09 20:54:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Add(const char *dir1, const char *dir2, const char *name, struct dirent *de)
|
|
|
|
{
|
1996-05-14 07:25:59 +00:00
|
|
|
change++;
|
1996-05-09 20:54:06 +00:00
|
|
|
if (de->d_type == DT_DIR) {
|
|
|
|
char *p = alloca(strlen(name)+strlen(de->d_name)+2);
|
1996-11-16 19:30:14 +00:00
|
|
|
strcpy(p, name); strcat(p, de->d_name); strcat(p, "/");
|
|
|
|
name_stat("CTMDM", dir2, name, de);
|
1996-05-09 20:54:06 +00:00
|
|
|
putchar('\n');
|
|
|
|
s_new_dirs++;
|
1996-11-16 19:30:14 +00:00
|
|
|
DoDir(dir1, dir2, p);
|
1996-05-09 20:54:06 +00:00
|
|
|
} else if (de->d_type == DT_REG) {
|
|
|
|
char *buf2 = alloca(strlen(dir2) + strlen(name) +
|
|
|
|
strlen(de->d_name) + 3);
|
|
|
|
char *m2, md5_2[33];
|
|
|
|
u_char *p1;
|
|
|
|
struct stat st;
|
|
|
|
int fd1;
|
|
|
|
|
1996-11-16 19:30:14 +00:00
|
|
|
strcpy(buf2, dir2);
|
|
|
|
strcat(buf2, "/"); strcat(buf2, name);
|
|
|
|
strcat(buf2, "/"); strcat(buf2, de->d_name);
|
|
|
|
fd1 = open(buf2, O_RDONLY);
|
1997-09-17 06:24:58 +00:00
|
|
|
if (fd1 < 0) { err(3, "%s", buf2); }
|
1996-11-16 19:30:14 +00:00
|
|
|
fstat(fd1, &st);
|
|
|
|
p1=mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd1, 0);
|
1997-09-17 06:24:58 +00:00
|
|
|
if (p1 == (u_char *)MAP_FAILED) { err(3, "%s", buf2); }
|
1996-05-09 20:54:06 +00:00
|
|
|
close(fd1);
|
|
|
|
m2 = MD5Data(p1, st.st_size, md5_2);
|
1996-11-16 19:30:14 +00:00
|
|
|
name_stat("CTMFM", dir2, name, de);
|
|
|
|
printf(" %s %u\n", m2, (unsigned)st.st_size);
|
|
|
|
fwrite(p1, 1, st.st_size, stdout);
|
1996-05-09 20:54:06 +00:00
|
|
|
putchar('\n');
|
1996-11-16 19:30:14 +00:00
|
|
|
munmap(p1, st.st_size);
|
1996-05-09 20:54:06 +00:00
|
|
|
s_new_files++;
|
|
|
|
s_new_bytes += st.st_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Del (const char *dir1, const char *dir2, const char *name, struct dirent *de)
|
|
|
|
{
|
1996-05-14 07:25:59 +00:00
|
|
|
damage++;
|
|
|
|
change++;
|
1996-05-09 20:54:06 +00:00
|
|
|
if (de->d_type == DT_DIR) {
|
|
|
|
char *p = alloca(strlen(name)+strlen(de->d_name)+2);
|
1996-11-16 19:30:14 +00:00
|
|
|
strcpy(p, name); strcat(p, de->d_name); strcat(p, "/");
|
|
|
|
DoDir(dir1, dir2, p);
|
|
|
|
printf("CTMDR %s%s\n", name, de->d_name);
|
|
|
|
fprintf(logf, "CTMDR %s%s\n", name, de->d_name);
|
|
|
|
if (verbose > 1) {
|
|
|
|
fprintf(stderr, "CTMDR %s%s\n", name, de->d_name);
|
|
|
|
}
|
1996-05-09 20:54:06 +00:00
|
|
|
s_del_dirs++;
|
|
|
|
} else if (de->d_type == DT_REG) {
|
|
|
|
char *buf1 = alloca(strlen(dir1) + strlen(name) +
|
|
|
|
strlen(de->d_name) + 3);
|
|
|
|
char *m1, md5_1[33];
|
1996-11-16 19:30:14 +00:00
|
|
|
strcpy(buf1, dir1);
|
|
|
|
strcat(buf1, "/"); strcat(buf1, name);
|
|
|
|
strcat(buf1, "/"); strcat(buf1, de->d_name);
|
1996-05-09 20:54:06 +00:00
|
|
|
m1 = MD5File(buf1, md5_1);
|
1996-11-16 19:30:14 +00:00
|
|
|
printf("CTMFR %s%s %s\n", name, de->d_name, m1);
|
|
|
|
fprintf(logf, "CTMFR %s%s %s\n", name, de->d_name, m1);
|
|
|
|
if (verbose > 1) {
|
|
|
|
fprintf(stderr, "CTMFR %s%s\n", name, de->d_name);
|
|
|
|
}
|
1996-05-09 20:54:06 +00:00
|
|
|
s_del_files++;
|
|
|
|
s_del_bytes += StatFile(buf1)->st_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetNext(int *i, int *n, struct dirent **nl, const char *dir, const char *name, u_long *ignored, u_long *bogus, u_long *wrong)
|
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
1996-11-16 22:05:46 +00:00
|
|
|
char buf1[BUFSIZ];
|
1996-05-09 20:54:06 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
for (;;) {
|
|
|
|
(*i)++;
|
|
|
|
if (*i >= *n)
|
|
|
|
return;
|
1996-11-16 22:05:46 +00:00
|
|
|
strcpy(buf1, name);
|
|
|
|
if (buf1[strlen(buf1)-1] != '/')
|
|
|
|
strcat(buf1, "/");
|
|
|
|
strcat(buf1, nl[*i]->d_name);
|
1996-05-14 07:25:59 +00:00
|
|
|
if (flag_ignore &&
|
1996-11-16 22:05:46 +00:00
|
|
|
!regexec(®_ignore, buf1, 0, 0, 0)) {
|
1996-05-09 20:54:06 +00:00
|
|
|
(*ignored)++;
|
1996-11-16 22:05:46 +00:00
|
|
|
fprintf(logf, "Ignore %s\n", buf1);
|
1996-05-14 07:25:59 +00:00
|
|
|
if (verbose > 2) {
|
1996-11-16 22:05:46 +00:00
|
|
|
fprintf(stderr, "Ignore %s\n", buf1);
|
1996-05-14 07:25:59 +00:00
|
|
|
}
|
|
|
|
} else if (flag_bogus &&
|
1996-11-16 22:05:46 +00:00
|
|
|
!regexec(®_bogus, buf1, 0, 0, 0)) {
|
1996-05-09 20:54:06 +00:00
|
|
|
(*bogus)++;
|
1996-11-16 22:05:46 +00:00
|
|
|
fprintf(logf, "Bogus %s\n", buf1);
|
|
|
|
fprintf(stderr, "Bogus %s\n", buf1);
|
1996-11-16 19:30:14 +00:00
|
|
|
damage++;
|
1996-05-14 07:25:59 +00:00
|
|
|
} else {
|
1996-11-16 22:05:46 +00:00
|
|
|
*buf = 0;
|
|
|
|
if (*dir != '/')
|
|
|
|
strcat(buf, "/");
|
|
|
|
strcat(buf, dir);
|
|
|
|
if (buf[strlen(buf)-1] != '/')
|
|
|
|
strcat(buf, "/");
|
|
|
|
strcat(buf, buf1);
|
1996-05-09 20:54:06 +00:00
|
|
|
break;
|
1996-05-14 07:25:59 +00:00
|
|
|
}
|
1996-05-09 20:54:06 +00:00
|
|
|
free(nl[*i]); nl[*i] = 0;
|
|
|
|
}
|
|
|
|
/* If the filesystem didn't tell us, find type */
|
|
|
|
if (nl[*i]->d_type == DT_UNKNOWN)
|
|
|
|
nl[*i]->d_type = IFTODT(StatFile(buf)->st_mode);
|
|
|
|
if (nl[*i]->d_type == DT_REG || nl[*i]->d_type == DT_DIR)
|
|
|
|
break;
|
|
|
|
(*wrong)++;
|
1996-05-14 07:25:59 +00:00
|
|
|
if (verbose > 0)
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(stderr, "Wrong %s\n", buf);
|
1996-05-09 20:54:06 +00:00
|
|
|
free(nl[*i]); nl[*i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DoDir(const char *dir1, const char *dir2, const char *name)
|
|
|
|
{
|
1996-11-16 19:30:14 +00:00
|
|
|
int i1, i2, n1, n2, i;
|
|
|
|
struct dirent **nl1, **nl2;
|
1996-05-09 20:54:06 +00:00
|
|
|
char *buf1 = alloca(strlen(dir1) + strlen(name) + 4);
|
|
|
|
char *buf2 = alloca(strlen(dir2) + strlen(name) + 4);
|
|
|
|
|
1996-11-16 19:30:14 +00:00
|
|
|
strcpy(buf1, dir1); strcat(buf1, "/"); strcat(buf1, name);
|
|
|
|
strcpy(buf2, dir2); strcat(buf2, "/"); strcat(buf2, name);
|
1996-05-09 20:54:06 +00:00
|
|
|
n1 = scandir(buf1, &nl1, dirselect, alphasort);
|
|
|
|
n2 = scandir(buf2, &nl2, dirselect, alphasort);
|
|
|
|
i1 = i2 = -1;
|
|
|
|
GetNext(&i1, &n1, nl1, dir1, name, &s1_ignored, &s1_bogus, &s1_wrong);
|
|
|
|
GetNext(&i2, &n2, nl2, dir2, name, &s2_ignored, &s2_bogus, &s2_wrong);
|
|
|
|
for (;i1 < n1 || i2 < n2;) {
|
|
|
|
|
1996-05-14 07:25:59 +00:00
|
|
|
if (damage_limit && damage > damage_limit)
|
|
|
|
break;
|
|
|
|
|
1996-05-09 20:54:06 +00:00
|
|
|
/* Get next item from list 1 */
|
|
|
|
if (i1 < n1 && !nl1[i1])
|
|
|
|
GetNext(&i1, &n1, nl1, dir1, name,
|
|
|
|
&s1_ignored, &s1_bogus, &s1_wrong);
|
|
|
|
|
|
|
|
/* Get next item from list 2 */
|
|
|
|
if (i2 < n2 && !nl2[i2])
|
|
|
|
GetNext(&i2, &n2, nl2, dir2, name,
|
|
|
|
&s2_ignored, &s2_bogus, &s2_wrong);
|
|
|
|
|
|
|
|
if (i1 >= n1 && i2 >= n2) {
|
|
|
|
/* Done */
|
|
|
|
break;
|
|
|
|
} else if (i1 >= n1 && i2 < n2) {
|
|
|
|
/* end of list 1, add anything left on list 2 */
|
1996-11-16 19:30:14 +00:00
|
|
|
Add(dir1, dir2, name, nl2[i2]);
|
1996-05-09 20:54:06 +00:00
|
|
|
free(nl2[i2]); nl2[i2] = 0;
|
|
|
|
} else if (i1 < n1 && i2 >= n2) {
|
|
|
|
/* end of list 2, delete anything left on list 1 */
|
1996-11-16 19:30:14 +00:00
|
|
|
Del(dir1, dir2, name, nl1[i1]);
|
1996-05-09 20:54:06 +00:00
|
|
|
free(nl1[i1]); nl1[i1] = 0;
|
|
|
|
} else if (!(i = strcmp(nl1[i1]->d_name, nl2[i2]->d_name))) {
|
|
|
|
/* Identical names */
|
|
|
|
if (nl1[i1]->d_type == nl2[i2]->d_type) {
|
|
|
|
/* same type */
|
1996-11-16 19:30:14 +00:00
|
|
|
Equ(dir1, dir2, name, nl1[i1]);
|
1996-05-09 20:54:06 +00:00
|
|
|
} else {
|
|
|
|
/* different types */
|
1996-11-16 19:30:14 +00:00
|
|
|
Del(dir1, dir2, name, nl1[i1]);
|
|
|
|
Add(dir1, dir2, name, nl2[i2]);
|
1996-05-09 20:54:06 +00:00
|
|
|
}
|
|
|
|
free(nl1[i1]); nl1[i1] = 0;
|
|
|
|
free(nl2[i2]); nl2[i2] = 0;
|
|
|
|
} else if (i < 0) {
|
|
|
|
/* Something extra in list 1, delete it */
|
1996-11-16 19:30:14 +00:00
|
|
|
Del(dir1, dir2, name, nl1[i1]);
|
1996-05-09 20:54:06 +00:00
|
|
|
free(nl1[i1]); nl1[i1] = 0;
|
|
|
|
} else {
|
|
|
|
/* Something extra in list 2, add it */
|
1996-11-16 19:30:14 +00:00
|
|
|
Add(dir1, dir2, name, nl2[i2]);
|
1996-05-09 20:54:06 +00:00
|
|
|
free(nl2[i2]); nl2[i2] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (n1 >= 0)
|
|
|
|
free(nl1);
|
|
|
|
if (n2 >= 0)
|
|
|
|
free(nl2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
|
|
|
|
1996-05-14 07:25:59 +00:00
|
|
|
setbuf(stderr, NULL);
|
|
|
|
|
1996-11-16 19:30:14 +00:00
|
|
|
#if 0
|
|
|
|
if (regcomp(®_bogus, DEFAULT_BOGUS, REG_EXTENDED | REG_NEWLINE))
|
1996-05-09 20:54:06 +00:00
|
|
|
/* XXX use regerror to explain it */
|
1997-09-17 06:24:58 +00:00
|
|
|
errx(1, "default regular expression argument to -B is botched");
|
1996-05-09 20:54:06 +00:00
|
|
|
flag_bogus = 1;
|
|
|
|
|
1996-11-16 19:30:14 +00:00
|
|
|
if (regcomp(®_ignore, DEFAULT_IGNORE, REG_EXTENDED | REG_NEWLINE))
|
1996-05-09 20:54:06 +00:00
|
|
|
/* XXX use regerror to explain it */
|
1997-09-17 06:24:58 +00:00
|
|
|
errx(1, "default regular expression argument to -I is botched");
|
1996-05-09 20:54:06 +00:00
|
|
|
flag_ignore = 1;
|
1996-11-16 19:30:14 +00:00
|
|
|
#endif
|
1996-05-09 20:54:06 +00:00
|
|
|
|
1997-03-31 05:11:47 +00:00
|
|
|
while ((i = getopt(argc, argv, "D:I:B:l:qv")) != -1)
|
1996-05-09 20:54:06 +00:00
|
|
|
switch (i) {
|
1996-05-14 07:25:59 +00:00
|
|
|
case 'D':
|
1996-11-16 19:30:14 +00:00
|
|
|
damage_limit = strtol(optarg, 0, 0);
|
1996-05-14 07:25:59 +00:00
|
|
|
if (damage_limit < 0)
|
1997-09-17 06:24:58 +00:00
|
|
|
errx(1, "damage limit must be positive");
|
1996-05-14 07:25:59 +00:00
|
|
|
break;
|
1996-05-09 20:54:06 +00:00
|
|
|
case 'I':
|
|
|
|
if (flag_ignore)
|
|
|
|
regfree(®_ignore);
|
|
|
|
flag_ignore = 0;
|
|
|
|
if (!*optarg)
|
|
|
|
break;
|
1996-11-16 19:30:14 +00:00
|
|
|
if (regcomp(®_ignore, optarg,
|
1996-05-09 20:54:06 +00:00
|
|
|
REG_EXTENDED | REG_NEWLINE))
|
|
|
|
/* XXX use regerror to explain it */
|
1997-09-17 06:24:58 +00:00
|
|
|
errx(1, "regular expression argument to -I is botched");
|
1996-05-09 20:54:06 +00:00
|
|
|
flag_ignore = 1;
|
|
|
|
break;
|
|
|
|
case 'B':
|
|
|
|
if (flag_bogus)
|
|
|
|
regfree(®_bogus);
|
|
|
|
flag_bogus = 0;
|
|
|
|
if (!*optarg)
|
|
|
|
break;
|
1996-11-16 19:30:14 +00:00
|
|
|
if (regcomp(®_bogus, optarg,
|
1996-05-09 20:54:06 +00:00
|
|
|
REG_EXTENDED | REG_NEWLINE))
|
|
|
|
/* XXX use regerror to explain it */
|
1997-09-17 06:24:58 +00:00
|
|
|
errx(1, "regular expression argument to -B is botched");
|
1996-05-09 20:54:06 +00:00
|
|
|
flag_bogus = 1;
|
|
|
|
break;
|
1996-11-16 19:30:14 +00:00
|
|
|
case 'l':
|
|
|
|
logf = fopen(optarg, "w");
|
|
|
|
if (!logf)
|
1997-09-17 06:24:58 +00:00
|
|
|
err(1, "%s", optarg);
|
1996-11-16 19:30:14 +00:00
|
|
|
break;
|
1996-05-14 07:25:59 +00:00
|
|
|
case 'q':
|
|
|
|
verbose--;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
1996-05-09 20:54:06 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
1996-05-14 07:25:59 +00:00
|
|
|
Usage();
|
1996-05-09 20:54:06 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1996-11-16 19:30:14 +00:00
|
|
|
if (!logf)
|
|
|
|
logf = fopen("/dev/null", "w");
|
|
|
|
|
|
|
|
setbuf(stdout, 0);
|
1996-05-09 20:54:06 +00:00
|
|
|
|
1996-05-14 07:25:59 +00:00
|
|
|
if (argc != 6) {
|
|
|
|
Usage();
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1996-11-16 19:30:14 +00:00
|
|
|
signal(SIGINFO, stat_info);
|
1996-05-14 07:25:59 +00:00
|
|
|
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(stderr, "CTM_BEGIN 2.0 %s %s %s %s\n",
|
|
|
|
argv[0], argv[1], argv[2], argv[3]);
|
|
|
|
fprintf(logf, "CTM_BEGIN 2.0 %s %s %s %s\n",
|
|
|
|
argv[0], argv[1], argv[2], argv[3]);
|
1996-05-14 07:25:59 +00:00
|
|
|
printf("CTM_BEGIN 2.0 %s %s %s %s\n",
|
|
|
|
argv[0], argv[1], argv[2], argv[3]);
|
1996-11-16 19:30:14 +00:00
|
|
|
DoDir(argv[4], argv[5], "");
|
1996-05-14 07:25:59 +00:00
|
|
|
if (damage_limit && damage > damage_limit) {
|
1996-11-16 19:30:14 +00:00
|
|
|
print_stat(stderr, "DAMAGE: ");
|
1997-09-17 06:24:58 +00:00
|
|
|
errx(1, "damage of %d would exceed %d files",
|
1996-11-16 19:30:14 +00:00
|
|
|
damage, damage_limit);
|
|
|
|
} else if (change < 2) {
|
1997-09-17 06:24:58 +00:00
|
|
|
errx(4, "no changes");
|
1996-05-14 07:25:59 +00:00
|
|
|
} else {
|
|
|
|
printf("CTM_END ");
|
1996-11-16 19:30:14 +00:00
|
|
|
fprintf(logf, "CTM_END\n");
|
|
|
|
print_stat(stderr, "END: ");
|
1996-05-14 07:25:59 +00:00
|
|
|
}
|
1996-05-09 20:54:06 +00:00
|
|
|
exit(0);
|
|
|
|
}
|