#include #include #include #include #include #include /* Added the leading rpm/ -DY 6-29-98 */ #include /* Added line -DY 6-29-98 */ #include /* Added line -DY 6-29-98 */ #include #include #include #include #include #define FILENAME_TAG 1000000 int tags[] = { RPMTAG_NAME, RPMTAG_VERSION, RPMTAG_RELEASE, RPMTAG_SERIAL, RPMTAG_FILENAMES, RPMTAG_FILESIZES, RPMTAG_GROUP, RPMTAG_REQUIREFLAGS, RPMTAG_REQUIRENAME, RPMTAG_REQUIREVERSION, RPMTAG_DESCRIPTION, RPMTAG_SUMMARY, RPMTAG_PROVIDES, RPMTAG_SIZE, RPMTAG_OBSOLETES }; int numTags = sizeof(tags) / sizeof(int); int main(int argc, char ** argv) { char buf[300]; DIR * dir; int outfd; struct dirent * ent; int fd, rc, isSource; Header h, newh; int count, type; int i; void * ptr; if (argc != 2) { fprintf(stderr, "usage: genhdlist \n"); exit(1); } strcpy(buf, argv[1]); strcat(buf, "/RedHat/RPMS"); dir = opendir(buf); if (!dir) { fprintf(stderr,"error opening directory %s: %s\n", buf, strerror(errno)); return 1; } chdir(buf); strcpy(buf, argv[1]); strcat(buf, "/RedHat/base/hdlist"); outfd = open(buf, O_WRONLY | O_TRUNC | O_CREAT, 0644); if (outfd < 0) { fprintf(stderr,"error creating file %s: %s\n", buf, strerror(errno)); return 1; } errno = 0; ent = readdir(dir); if (errno) { perror("readdir"); return 1; } while (ent) { if (!(ent->d_name[0] == '.' && (ent->d_name[1] == '\0' || ((ent->d_name[1] == '.') && (ent->d_name[2] == '\0'))))) { fd = open(ent->d_name, O_RDONLY); if (fd < 0) { perror("open"); exit(1); } rc = rpmReadPackageHeader(fd, &h, &isSource, NULL, NULL); close(fd); if (rc) { fprintf(stderr, "failed to rpmReadPackageHeader %s\n", ent->d_name); exit(1); } /* Regular bit */ newh = headerNew(); for (i = 0; i < numTags; i++) { if (!headerGetEntry(h, tags[i], &type, &ptr, &count)) { switch (tags[i]) { case RPMTAG_REQUIREFLAGS: case RPMTAG_REQUIRENAME: case RPMTAG_REQUIREVERSION: case RPMTAG_FILENAMES: case RPMTAG_FILESIZES: case RPMTAG_SUMMARY: case RPMTAG_SERIAL: case RPMTAG_PROVIDES: case RPMTAG_OBSOLETES: break; default: fprintf(stderr, "tag %d not found in file %s\n", tags[i], ent->d_name); exit(1); } } else headerAddEntry(newh, tags[i], type, ptr, count); } headerAddEntry(newh, FILENAME_TAG, RPM_STRING_TYPE, ent->d_name, 1); headerWrite(outfd, newh, HEADER_MAGIC_YES); headerFree(newh); headerFree(h); } errno = 0; ent = readdir(dir); if (errno) { perror("readdir"); return 1; } } closedir(dir); close(outfd); return 0; }