本文整理汇总了C++中pkgdb_open函数的典型用法代码示例。如果您正苦于以下问题:C++ pkgdb_open函数的具体用法?C++ pkgdb_open怎么用?C++ pkgdb_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pkgdb_open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fix_deps
static int
fix_deps(struct pkgdb *db, struct deps_head *dh, int nbpkgs, bool yes)
{
struct pkg_jobs *jobs = NULL;
struct deps_entry *e = NULL;
char **pkgs = NULL;
int i = 0;
pkg_flags f = PKG_FLAG_AUTOMATIC;
assert(db != NULL);
assert(nbpkgs > 0);
if ((pkgs = calloc(nbpkgs, MAXPATHLEN + 1)) == NULL)
err(1, "calloc()");
STAILQ_FOREACH(e, dh, next)
pkgs[i++] = e->origin;
if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {
free(pkgs);
return (EPKG_ENODB);
}
if (pkg_jobs_new(&jobs, PKG_JOBS_INSTALL, db) != EPKG_OK) {
free(pkgs);
return (EPKG_FATAL);
}
pkg_jobs_set_flags(jobs, f);
if (pkg_jobs_add(jobs, MATCH_EXACT, pkgs, nbpkgs) == EPKG_FATAL) {
pkg_jobs_free(jobs);
return (EPKG_FATAL);
}
if (pkg_jobs_solve(jobs) != EPKG_OK) {
pkg_jobs_free(jobs);
return (EPKG_FATAL);
}
if (pkg_jobs_count(jobs) == 0) {
printf("\nUnable to find packages for installation.\n\n");
pkg_jobs_free(jobs);
return (EPKG_FATAL);
}
/* print a summary before applying the jobs */
print_jobs_summary(jobs, "The following packages will be installed:\n\n");
if (yes == false)
yes = query_yesno("\n>>> Try to fix the missing dependencies [y/N]: ");
if (yes == true)
pkg_jobs_apply(jobs);
free(pkgs);
pkg_jobs_free(jobs);
return (EPKG_OK);
}
示例2: ldhdr_bynevr
static Header ldhdr_bynevr(const struct pkg *pkg, void *foo)
{
struct pm_ctx *pmctx;
struct pkgdb *db;
struct pm_dbrec dbrec;
Header h = NULL;
DBGF("%s\n", pkg_snprintf_s(pkg));
foo = foo;
pmctx = pm_new("rpm");
db = pkgdb_open(pmctx, "/", NULL, O_RDONLY, NULL);
if (db == NULL)
goto l_end;
if (pkgdb_get_package_hdr(db, pkg, &dbrec)) {
n_assert(dbrec.hdr);
h = pm_rpmhdr_link(dbrec.hdr);
}
pkgdb_free(db);
l_end:
pm_free(pmctx);
return h;
}
示例3: ldhdr_byrecno
static Header ldhdr_byrecno(const struct pkg *pkg, void *foo)
{
struct pm_ctx *pmctx;
struct pkgdb *db;
struct pkgdb_it it;
const struct pm_dbrec *dbrec;
Header h = NULL;
foo = foo;
n_assert(pkg->recno > 0);
pmctx = pm_new("rpm");
db = pkgdb_open(pmctx, "/", NULL, O_RDONLY, NULL);
if (db == NULL)
goto l_end;
pkgdb_it_init(db, &it, PMTAG_RECNO, (const char*)&pkg->recno);
if ((dbrec = pkgdb_it_get(&it)) == NULL)
goto l_end;
// rpm's error: rpmdb_it_get_count(&it) with RECNO is always 0
if (dbrec->hdr)
h = pm_rpmhdr_link(dbrec->hdr);
pkgdb_it_destroy(&it);
pkgdb_free(db);
l_end:
pm_free(pmctx);
return h;
}
示例4: exec_backup
int
exec_backup(int argc, char **argv)
{
struct pkgdb *db = NULL;
char *backup_file = NULL;
bool dump = false;
bool restore = false;
int ch;
struct option longopts[] = {
{ "dump", required_argument, NULL, 'd' },
{ "restore", required_argument, NULL, 'r' },
{ NULL, 0, NULL, 0 },
};
while ((ch = getopt_long(argc, argv, "+d:r:", longopts, NULL)) != -1) {
switch (ch) {
case 'd':
dump = true;
backup_file = optarg;
break;
case 'r':
restore = true;
backup_file = optarg;
break;
default:
usage_backup();
return (EX_USAGE);
}
}
argc -= optind;
argv += optind;
if ( dump == restore ) {
usage_backup();
return (EX_USAGE);
}
if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
return (EX_IOERR);
if (dump) {
if (isatty(fileno(stdout)))
printf("Dumping database:\n");
if (pkgdb_dump(db, backup_file) == EPKG_FATAL)
return (EX_IOERR);
}
if (restore) {
if (!quiet)
printf("Restoring database:\n");
if (pkgdb_load(db, backup_file) == EPKG_FATAL)
return (EX_IOERR);
}
pkgdb_close(db);
return (EX_OK);
}
示例5: delete1pkg
static void
delete1pkg(const char *pkgdir)
{
if (!pkgdb_open(ReadWrite))
err(EXIT_FAILURE, "cannot open pkgdb");
(void) pkgdb_remove_pkg(pkgdir);
pkgdb_close();
}
示例6: fix_deps
static int
fix_deps(struct pkgdb *db, struct deps_head *dh, int nbpkgs, bool yes)
{
struct pkg *pkg = NULL;
struct pkgdb_it *it = NULL;
struct pkg_jobs *jobs = NULL;
struct deps_entry *e = NULL;
char **pkgs = NULL;
int i = 0;
assert(db != NULL);
assert(nbpkgs > 0);
if ((pkgs = calloc(nbpkgs, MAXPATHLEN + 1)) == NULL)
err(1, "calloc()");
STAILQ_FOREACH(e, dh, next)
pkgs[i++] = e->origin;
if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK)
return (EPKG_ENODB);
if (pkg_jobs_new(&jobs, PKG_JOBS_INSTALL, db) != EPKG_OK)
free(pkgs);
if ((it = pkgdb_query_installs(db, MATCH_EXACT, nbpkgs, pkgs, NULL, false)) == NULL) {
free(pkgs);
pkg_jobs_free(jobs);
}
while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC|PKG_LOAD_DEPS) == EPKG_OK) {
pkg_jobs_add(jobs, pkg);
pkg = NULL;
}
if (pkg_jobs_is_empty(jobs)) {
printf("\n>>> Unable to find packages for installation.\n\n");
return (EPKG_FATAL);
}
/* print a summary before applying the jobs */
pkg = NULL;
print_jobs_summary(jobs, PKG_JOBS_INSTALL, "The following packages will be installed:\n\n");
if (yes == false)
yes = query_yesno("\n>>> Try to fix the missing dependencies [y/N]: ");
if (yes == true)
pkg_jobs_apply(jobs, 0);
free(pkgs);
pkg_free(pkg);
pkg_jobs_free(jobs);
pkgdb_it_free(it);
return (EPKG_OK);
}
示例7: exec_add
int
exec_add(int argc, char **argv)
{
struct pkgdb *db = NULL;
struct sbuf *failedpkgs = sbuf_new_auto();
char path[MAXPATHLEN + 1];
char *file;
int retcode = EPKG_OK;
int i;
int failedpkgcount = 0;
struct pkg *p = NULL;
if (argc < 2) {
usage_add();
return (EX_USAGE);
}
if (geteuid() != 0) {
warnx("adding packages can only be done as root");
return (EX_NOPERM);
}
if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
return (EX_IOERR);
}
for (i = 1; i < argc; i++) {
if (is_url(argv[i]) == EPKG_OK) {
snprintf(path, sizeof(path), "./%s", basename(argv[i]));
if ((retcode = pkg_fetch_file(argv[i], path)) != EPKG_OK)
break;
file = path;
} else
file = argv[i];
pkg_open(&p, file, NULL);
if ((retcode = pkg_add(db, file, 0)) != EPKG_OK) {
sbuf_cat(failedpkgs, argv[i]);
if (i != argc - 1)
sbuf_printf(failedpkgs, ", ");
failedpkgcount++;
}
}
pkgdb_close(db);
if(failedpkgcount > 0) {
sbuf_finish(failedpkgs);
printf("Failed to install the following %d package(s): %s.\n", failedpkgcount, sbuf_data(failedpkgs));
}
sbuf_delete(failedpkgs);
return (retcode == EPKG_OK ? EX_OK : EX_SOFTWARE);
}
示例8: pkg_create_matches
static int
pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt, const char * const outdir, const char * const rootdir)
{
int i, ret = EPKG_OK, retcode = EPKG_OK;
struct pkgdb *db = NULL;
struct pkgdb_it *it = NULL;
struct pkg *pkg = NULL;
int query_flags = PKG_LOAD_DEPS | PKG_LOAD_CONFLICTS | PKG_LOAD_FILES | PKG_LOAD_CATEGORIES |
PKG_LOAD_DIRS | PKG_LOAD_SCRIPTS | PKG_LOAD_OPTIONS |
PKG_LOAD_MTREE | PKG_LOAD_LICENSES;
if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
pkgdb_close(db);
return (EX_IOERR);
}
if (match != MATCH_ALL) {
for (i = 0;i < argc; i++) {
if ((it = pkgdb_query(db, argv[i], match)) == NULL) {
goto cleanup;
}
while ((ret = pkgdb_it_next(it, &pkg, query_flags)) == EPKG_OK) {
printf("Creating package for %s-%s\n", pkg_get(pkg, PKG_NAME),
pkg_get(pkg, PKG_VERSION));
if (pkg_create_installed(outdir, fmt, rootdir, pkg) != EPKG_OK) {
retcode++;
}
}
}
} else {
if ((it = pkgdb_query(db, NULL, match)) == NULL) {
goto cleanup;
}
while ((ret = pkgdb_it_next(it, &pkg, query_flags)) == EPKG_OK) {
printf("Creating package for %s-%s\n", pkg_get(pkg, PKG_NAME),
pkg_get(pkg, PKG_VERSION));
if (pkg_create_installed(outdir, fmt, rootdir, pkg) != EPKG_OK) {
retcode++;
}
}
}
cleanup:
if (ret != EPKG_END) {
retcode++;
}
pkg_free(pkg);
pkgdb_it_free(it);
pkgdb_close(db);
return (retcode);
}
示例9: exec_stats
int
exec_stats(int argc, char **argv)
{
struct pkgdb *db = NULL;
int64_t flatsize = 0;
char size[7];
int retcode = EX_OK;
int ch;
while ((ch = getopt(argc, argv, "q")) != -1) {
switch (ch) {
case 'q':
quiet = true;
break;
default:
usage_stats();
return (EX_USAGE);
}
}
argc -= optind;
argv += optind;
if (argc > 2) {
usage_stats();
return (EX_USAGE);
}
if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK) {
return (EX_IOERR);
}
printf("Local package database:\n");
printf("\tInstalled packages: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_LOCAL_COUNT));
flatsize = pkgdb_stats(db, PKG_STATS_LOCAL_SIZE);
humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0);
printf("\tDisk space occupied: %s\n\n", size);
printf("Remote package database(s):\n");
printf("\tNumber of repositories: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_REPOS));
printf("\tPackages available: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_COUNT));
printf("\tUnique packages: %" PRId64 "\n", pkgdb_stats(db, PKG_STATS_REMOTE_UNIQUE));
flatsize = pkgdb_stats(db, PKG_STATS_REMOTE_SIZE);
humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0);
printf("\tTotal size of packages: %s\n", size);
pkgdb_close(db);
return (retcode);
}
示例10: exec_shlib
int
exec_shlib(int argc, char **argv)
{
struct pkgdb *db = NULL;
char libname[MAXPATHLEN + 1];
int retcode = EPKG_OK;
int ch;
bool provides_only = false;
bool requires_only = false;
while ((ch = getopt(argc, argv, "PR")) != -1) {
switch (ch) {
case 'P':
provides_only = true;
break;
case 'R':
requires_only = true;
break;
default:
usage_shlib();
return (EX_USAGE);
}
}
argc -= optind;
argv += optind;
if (argc < 1 || (provides_only && requires_only)) {
usage_shlib();
return (EX_USAGE);
}
if (sanitize(libname, argv[0], sizeof(libname)) == NULL) {
usage_shlib();
return (EX_USAGE);
}
retcode = pkgdb_open(&db, PKGDB_DEFAULT);
if (retcode == EPKG_OK && !provides_only)
retcode = pkgs_providing_lib(db, libname);
if (retcode == EPKG_OK && !requires_only)
retcode = pkgs_requiring_lib(db, libname);
if (retcode != EPKG_OK)
retcode = (EX_IOERR);
pkgdb_close(db);
return (retcode);
}
示例11: load_db_packages
static
int load_db_packages(struct pm_ctx *pmctx, struct pkgdir *pkgdir,
const char *rootdir)
{
struct pkgdb *db;
struct pkgdb_it it;
const struct pm_dbrec *dbrec;
char dbfull_path[PATH_MAX];
int n;
snprintf(dbfull_path, sizeof(dbfull_path), "%s%s",
*(rootdir + 1) == '\0' ? "" : rootdir,
pkgdir->idxpath != NULL ? pkgdir->idxpath : "");
db = pkgdb_open(pmctx, rootdir, pkgdir->idxpath, O_RDONLY, NULL);
if (db == NULL)
return 0;
msg(3, _("Loading db packages%s%s%s..."), *dbfull_path ? " [":"",
dbfull_path, *dbfull_path ? "]":"");
pkgdb_it_init(db, &it, PMTAG_RECNO, NULL);
n = 0;
while ((dbrec = pkgdb_it_get(&it))) {
if (dbrec->hdr) {
if (load_package(dbrec->recno, dbrec->hdr, pkgdir))
n++;
}
if (n % 100 == 0)
msg(3, "_.");
if (sigint_reached()) {
n = 0;
break;
}
}
msgn(3, "_done");
pkgdb_it_destroy(&it);
pkgdb_free(db);
if (n == 0)
n_array_clean(pkgdir->pkgs);
return n_array_size(pkgdir->pkgs);
}
示例12: do_open
/* just check if database exists */
static
int do_open(struct pkgdir *pkgdir, unsigned flags)
{
struct pm_ctx *pmctx;
struct pkgdb *db;
flags = flags; /* unused */
n_assert(pkgdir->mod_data == NULL);
pkgdir->mod_data = pmctx = pm_new("rpm");
if ((db = pkgdb_open(pmctx, "/", pkgdir->idxpath, O_RDONLY, NULL)) == NULL)
return 0;
pkgdb_free(db);
return 1;
}
示例13: pkgdb_dump
/* dump contents of the database to stdout */
int
pkgdb_dump(void)
{
DBT key;
DBT val;
int type;
if (pkgdb_open(ReadOnly)) {
for (type = R_FIRST ; (*pkgdbp->seq)(pkgdbp, &key, &val, type) == 0 ; type = R_NEXT) {
printf("file: %.*s pkg: %.*s\n",
(int) key.size, (char *) key.data,
(int) val.size, (char *) val.data);
}
pkgdb_close();
return 0;
} else
return -1;
}
示例14: getdb
int
getdb(struct pkgdb **db)
{
int err;
/* err = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_REPO);
if (err == EPKG_ENOACCESS)
fprintf(stderr, "check your privilege\n", err);
else if (err != EPKG_OK)
fprintf(stderr, "access error: %i\n", err);
else */{
err = pkgdb_open(db, PKGDB_REMOTE);
if (err != EPKG_OK)
fprintf(stderr, "open error: %i\n", err);
}
return err;
}
示例15: exec_which
int
exec_which(int argc, char **argv)
{
struct pkgdb *db;
struct pkgdb_it *it;
struct pkg *pkg = NULL;
char pathabs[MAXPATHLEN + 1];
int ret = EPKG_OK, retcode = EPKG_OK;
const char *name, *version;
if (argc != 2) {
usage_which();
return (EX_USAGE);
}
if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
pkgdb_close(db);
return (EX_IOERR);
}
absolutepath(argv[1], pathabs, sizeof(pathabs));
if ((it = pkgdb_query_which(db, pathabs)) == NULL) {
return (EX_IOERR);
}
if (( ret = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
retcode = EPKG_OK;
pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version);
printf("%s was installed by package %s-%s\n", pathabs, name, version);
} else if (ret != EPKG_END) {
retcode = EPKG_WARN;
} else {
printf("%s was not found in the database\n", pathabs);
retcode = EPKG_WARN;
}
pkg_free(pkg);
pkgdb_it_free(it);
pkgdb_close(db);
return (retcode);
}