static void rebuild_tree(void) { if (iterate_pkg_db(remove_required_by, NULL) == -1) errx(EXIT_FAILURE, "cannot iterate pkgdb"); if (iterate_pkg_db(add_depends_of, NULL) == -1) errx(EXIT_FAILURE, "cannot iterate pkgdb"); }
static void rebuild(void) { char *cachename; struct pkgdb_count count; count.files = 0; count.directories = 0; count.packages = 0; cachename = pkgdb_get_database(); if (unlink(cachename) != 0 && errno != ENOENT) err(EXIT_FAILURE, "unlink %s", cachename); setbuf(stdout, NULL); iterate_pkg_db(add_pkg, &count); printf("\n"); printf("Stored %" PRIzu " file%s and %" PRIzu " explicit director%s" " from %"PRIzu " package%s in %s.\n", count.files, count.files == 1 ? "" : "s", count.directories, count.directories == 1 ? "y" : "ies", count.packages, count.packages == 1 ? "" : "s", cachename); }
/* * Find all packages that match the given pattern and call the function * for each of them. Iteration stops if the callback return non-0. * Returns -1 on error, 0 if the iteration finished or whatever the * callback returned otherwise. */ int match_installed_pkgs(const char *pattern, int (*cb)(const char *, void *), void *cookie) { struct call_matching_arg arg; arg.pattern = pattern; arg.call_fn = cb; arg.cookie = cookie; return iterate_pkg_db(match_and_call, &arg); }
/* * Returns a copy of the name of best matching package. * If no package matched the pattern or an error occured, return NULL. */ char * find_best_matching_installed_pkg(const char *pattern) { struct best_installed_match_arg arg; arg.pattern = pattern; arg.best_current_match = NULL; if (iterate_pkg_db(match_best_installed, &arg) == -1) { warnx("could not process pkgdb"); return NULL; } return arg.best_current_match; }
/* * Match all installed packages against pattern, add the matches to pkghead. * Returns -1 on error, 0 if no match was found and 1 otherwise. */ int add_installed_pkgs_by_pattern(const char *pattern, lpkg_head_t *pkghead) { struct add_matching_arg arg; arg.pkghead = pkghead; arg.got_match = 0; arg.match_fn = match_by_pattern; arg.cookie = __UNCONST(pattern); if (iterate_pkg_db(match_and_add, &arg) == -1) { warnx("could not process pkgdb"); return -1; } return arg.got_match; }
/** * Checks if some installed package has a pkgcfl entry that matches * PkgName. If such an entry is found, the package name is returned in * inst_pkgname, the matching pattern in inst_pattern, and the function * returns a non-zero value. Otherwise, zero is returned and the result * variables are set to NULL. */ int some_installed_package_conflicts_with(const char *pkgname, const char *skip_pkgname, char **inst_pkgname, char **inst_pattern) { struct package_conflict cfl; int rv; cfl.pkgname = pkgname; cfl.skip_pkgname = skip_pkgname; *inst_pkgname = NULL; *inst_pattern = NULL; cfl.conflicting_pkgname = inst_pkgname; cfl.conflicting_pattern = inst_pattern; rv = iterate_pkg_db(check_package_conflict, &cfl); if (rv == -1) { errx(EXIT_FAILURE, "Couldn't read list of installed packages."); /* NOTREACHED */ } return *inst_pkgname != NULL; }
static void rebuild(void) { char cachename[MaxPathSize]; int pkgcnt, filecnt; pkgcnt = 0; filecnt = 0; (void) _pkgdb_getPKGDB_FILE(cachename, sizeof(cachename)); if (unlink(cachename) != 0 && errno != ENOENT) err(EXIT_FAILURE, "unlink %s", cachename); setbuf(stdout, NULL); iterate_pkg_db(add_pkg, &filecnt); printf("\n"); printf("Stored %d file%s from %d package%s in %s.\n", filecnt, filecnt == 1 ? "" : "s", pkgcnt, pkgcnt == 1 ? "" : "s", cachename); }