/* * Check a list for files that require preconversion */ void check_list(package_t *pkg, const char *PkgName) { struct stat st; plist_t *tmp; plist_t *p; char buf[ChecksumHeaderLen + LegibleChecksumLen]; char target[MaxPathSize + SymlinkHeaderLen]; char name[MaxPathSize]; char *cwd = NULL; char *srcdir = NULL; int dirc; int cc; /* Open Package Database for writing */ if (update_pkgdb && !pkgdb_open(ReadWrite)) err(EXIT_FAILURE, "can't open pkgdb"); for (dirc = 0, p = pkg->head; p; p = p->next) { switch (p->type) { case PLIST_CWD: cwd = p->name; break; case PLIST_IGNORE: p = p->next; break; case PLIST_SRC: srcdir = p->name; break; case PLIST_DIR_RM: dirc++; break; case PLIST_FILE: /* * pkgdb handling - usually, we enter files * into the pkgdb as soon as they hit the disk, * but as they are present before pkg_create * starts, it's ok to do this somewhere here */ if (cwd == NULL) errx(2, "file without preceding @cwd found"); if (update_pkgdb) { char *s, t[MaxPathSize]; (void) snprintf(t, sizeof(t), "%s%s%s", cwd, (strcmp(cwd, "/") == 0) ? "" : "/", p->name); s = pkgdb_retrieve(t); if (s && PlistOnly) warnx("Overwriting %s - " "pkg %s bogus/conflicting?", t, s); else { pkgdb_store(t, PkgName); } } /* prepend DESTDIR if set? - HF */ (void) snprintf(name, sizeof(name), "%s%s%s", cwd, (strcmp(cwd, "/") == 0) ? "" : "/", p->name); if (lstat(name, &st) < 0) { warnx("can't stat `%s'", name); continue; } switch (st.st_mode & S_IFMT) { case S_IFDIR: p->type = PLIST_DIR_RM; dirc++; continue; case S_IFLNK: if (RelativeLinks) { CheckSymlink(name, cwd, strlen(cwd)); } (void) strlcpy(target, SYMLINK_HEADER, sizeof(target)); if ((cc = readlink(name, &target[SymlinkHeaderLen], sizeof(target) - SymlinkHeaderLen - 1)) < 0) { warnx("can't readlink `%s'", name); continue; } target[SymlinkHeaderLen + cc] = 0x0; tmp = new_plist_entry(); tmp->name = xstrdup(target); tmp->type = PLIST_COMMENT; tmp->next = p->next; tmp->prev = p; if (p == pkg->tail) { pkg->tail = tmp; } p->next = tmp; p = tmp; break; case S_IFCHR: warnx("Warning - char special device `%s' in PLIST", name); break; case S_IFBLK: warnx("Warning - block special device `%s' in PLIST", name); break; default: (void) strlcpy(buf, CHECKSUM_HEADER, sizeof(buf)); if (MD5File(name, &buf[ChecksumHeaderLen]) != (char *) NULL) { tmp = new_plist_entry(); tmp->name = xstrdup(buf); tmp->type = PLIST_COMMENT; /* PLIST_MD5 - HF */ tmp->next = p->next; tmp->prev = p; if (p == pkg->tail) { pkg->tail = tmp; } p->next = tmp; p = tmp; } break; } break; default: break; } } if (update_pkgdb) { pkgdb_close(); } if (ReorderDirs && dirc > 0) { reorder(pkg, dirc); } }
/* * Check a list for files that require preconversion */ void check_list(package_t *pkg, const char *PkgName) { struct stat st; plist_t *tmp; plist_t *p; char buf[ChecksumHeaderLen + LegibleChecksumLen]; char target[MaxPathSize + SymlinkHeaderLen]; char name[MaxPathSize]; char *cwd = NULL; char *pkgname = NULL; int cc; for (p = pkg->head; p; p = p->next) { switch (p->type) { case PLIST_CWD: cwd = p->name; break; case PLIST_NAME: pkgname = p->name; break; case PLIST_IGNORE: p = p->next; break; case PLIST_PKGDIR: if (cwd == NULL) errx(2, "@pkgdir without preceding @cwd found"); if (pkgname == NULL) errx(2, "@pkgdir without preceding @name found"); break; case PLIST_FILE: if (cwd == NULL) errx(2, "file without preceding @cwd found"); (void) snprintf(name, sizeof(name), "%s%s%s", cwd, (strcmp(cwd, "/") == 0) ? "" : "/", p->name); if (lstat(name, &st) < 0) { warnx("can't stat `%s'", name); continue; } switch (st.st_mode & S_IFMT) { case S_IFDIR: warnx("Warning - directory `%s' in PLIST", name); break; case S_IFLNK: if (RelativeLinks) { CheckSymlink(name, cwd, strlen(cwd)); } (void) strlcpy(target, SYMLINK_HEADER, sizeof(target)); if ((cc = readlink(name, &target[SymlinkHeaderLen], sizeof(target) - SymlinkHeaderLen - 1)) < 0) { warnx("can't readlink `%s'", name); continue; } target[SymlinkHeaderLen + cc] = 0x0; tmp = new_plist_entry(); tmp->name = xstrdup(target); tmp->type = PLIST_COMMENT; tmp->next = p->next; tmp->prev = p; if (p == pkg->tail) { pkg->tail = tmp; } p->next = tmp; p = tmp; break; case S_IFCHR: warnx("Warning - char special device `%s' in PLIST", name); break; case S_IFBLK: warnx("Warning - block special device `%s' in PLIST", name); break; default: (void) strlcpy(buf, CHECKSUM_HEADER, sizeof(buf)); if (MD5File(name, &buf[ChecksumHeaderLen]) != (char *) NULL) { tmp = new_plist_entry(); tmp->name = xstrdup(buf); tmp->type = PLIST_COMMENT; /* PLIST_MD5 - HF */ tmp->next = p->next; tmp->prev = p; if (p == pkg->tail) { pkg->tail = tmp; } p->next = tmp; p = tmp; } break; } break; default: break; } } }