void delete_pkgdir(const char *pkg, const char *prefix, const char *path) { size_t pkg_len, len; char *fullpath, *oldvalue, *newvalue, *iter; fullpath = xasprintf("%s/%s", prefix, path); oldvalue = pkgdb_retrieve(fullpath); if (oldvalue && strncmp(oldvalue, "@pkgdir ", 8) == 0) { newvalue = xstrdup(oldvalue); iter = newvalue + 8; pkg_len = strlen(pkg); while (*iter) { if (strncmp(iter, pkg, pkg_len) == 0 && (iter[pkg_len] == ' ' || iter[pkg_len] == '\0')) { len = strlen(iter + pkg_len); memmove(iter, iter + pkg_len + 1, len); if (len == 0) *iter = '\0'; } else { iter += strcspn(iter, " "); iter += strspn(iter, " "); } } pkgdb_remove(fullpath); if (iter != newvalue + 8) pkgdb_store(fullpath, newvalue); free(newvalue); } free(fullpath); }
void add_pkgdir(const char *pkg, const char *prefix, const char *path) { char *fullpath, *oldvalue, *newvalue; fullpath = xasprintf("%s/%s", prefix, path); oldvalue = pkgdb_retrieve(fullpath); if (oldvalue) { if (strncmp(oldvalue, "@pkgdir ", 8) != 0) errx(EXIT_FAILURE, "Internal error while processing pkgdb, run pkg_admin rebuild"); newvalue = xasprintf("%s %s", oldvalue, pkg); pkgdb_remove(fullpath); } else { newvalue = xasprintf("@pkgdir %s", pkg); } pkgdb_store(fullpath, newvalue); free(fullpath); free(newvalue); }
/* * add1pkg(<pkg>) * adds the files listed in the +CONTENTS of <pkg> into the * pkgdb.byfile.db database file in the current package dbdir. It * returns the number of files added to the database file. */ static int add_pkg(const char *pkgdir, void *vp) { FILE *f; plist_t *p; package_t Plist; char *contents; char *PkgName, *dirp; char file[MaxPathSize]; struct pkgdb_count *count; if (!pkgdb_open(ReadWrite)) err(EXIT_FAILURE, "cannot open pkgdb"); count = vp; ++count->packages; contents = pkgdb_pkg_file(pkgdir, CONTENTS_FNAME); if ((f = fopen(contents, "r")) == NULL) errx(EXIT_FAILURE, "%s: can't open `%s'", pkgdir, CONTENTS_FNAME); free(contents); read_plist(&Plist, f); if ((p = find_plist(&Plist, PLIST_NAME)) == NULL) { errx(EXIT_FAILURE, "Package `%s' has no @name, aborting.", pkgdir); } PkgName = p->name; dirp = NULL; for (p = Plist.head; p; p = p->next) { switch(p->type) { case PLIST_FILE: if (dirp == NULL) { errx(EXIT_FAILURE, "@cwd not yet found, please send-pr!"); } (void) snprintf(file, sizeof(file), "%s/%s", dirp, p->name); if (!(isfile(file) || islinktodir(file))) { if (isbrokenlink(file)) { warnx("%s: Symlink `%s' exists and is in %s but target does not exist!", PkgName, file, CONTENTS_FNAME); } else { warnx("%s: File `%s' is in %s but not on filesystem!", PkgName, file, CONTENTS_FNAME); } } else { pkgdb_store(file, PkgName); ++count->files; } break; case PLIST_PKGDIR: add_pkgdir(PkgName, dirp, p->name); ++count->directories; break; case PLIST_CWD: if (strcmp(p->name, ".") != 0) dirp = p->name; else dirp = pkgdb_pkg_dir(pkgdir); break; case PLIST_IGNORE: p = p->next; break; case PLIST_SHOW_ALL: case PLIST_SRC: case PLIST_CMD: case PLIST_CHMOD: case PLIST_CHOWN: case PLIST_CHGRP: case PLIST_COMMENT: case PLIST_NAME: case PLIST_UNEXEC: case PLIST_DISPLAY: case PLIST_PKGDEP: case PLIST_DIR_RM: case PLIST_OPTION: case PLIST_PKGCFL: case PLIST_BLDDEP: break; } } free_plist(&Plist); fclose(f); pkgdb_close(); return 0; }
/* * 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); } }