本文整理汇总了C++中pkgdb_close函数的典型用法代码示例。如果您正苦于以下问题:C++ pkgdb_close函数的具体用法?C++ pkgdb_close怎么用?C++ pkgdb_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pkgdb_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: delete1pkg
static void
delete1pkg(const char *pkgdir)
{
if (!pkgdb_open(ReadWrite))
err(EXIT_FAILURE, "cannot open pkgdb");
(void) pkgdb_remove_pkg(pkgdir);
pkgdb_close();
}
示例4: 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);
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
示例8: update_iinf
static void update_iinf(struct i3ctx *ictx, int vrfy)
{
int i, is_installed = 1;
const tn_array *unpkgs = iset_packages(ictx->unset);
const tn_array *inpkgs = iset_packages(ictx->inset);
if (vrfy)
pkgdb_reopen(ictx->ts->db, O_RDONLY);
for (i=0; i < n_array_size(inpkgs); i++) {
struct pkg *pkg = n_array_nth(inpkgs, i);
if (vrfy) {
int cmprc = 0;
is_installed = i3_is_pkg_installed(ictx->ts, pkg, &cmprc);
if (is_installed && cmprc != 0)
is_installed = 0;
}
if (is_installed)
n_array_push(ictx->ts->pkgs_installed, pkg_link(pkg));
}
if (vrfy == 0)
is_installed = 0;
for (i=0; i < n_array_size(unpkgs); i++) {
struct pkg *dbpkg = n_array_nth(unpkgs, i);
struct pkg *pkg = dbpkg;
if (vrfy) {
int cmprc = 0;
is_installed = i3_is_pkg_installed(ictx->ts, pkg, &cmprc);
if (is_installed && cmprc != 0)
is_installed = 0;
}
if (is_installed == 0)
n_array_push(ictx->ts->pkgs_removed, pkg_link(pkg));
}
if (vrfy)
pkgdb_close(ictx->ts->db);
}
示例9: 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;
}
示例10: list_locked
static int
list_locked(struct pkgdb *db)
{
struct pkgdb_it *it = NULL;
struct pkg *pkg = NULL;
if ((it = pkgdb_query(db, " where locked=1", MATCH_CONDITION)) == NULL) {
pkgdb_close(db);
return (EX_UNAVAILABLE);
}
printf("Currently locked packages:\n");
while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) == EPKG_OK) {
pkg_printf("%n-%v\n", pkg, pkg);
}
return (EX_OK);
}
示例11: remote_add_indexes
/* Add indexes to the repo */
static int
remote_add_indexes(const char *reponame)
{
struct pkgdb *db = NULL;
int ret = EPKG_FATAL;
if (pkgdb_open(&db, PKGDB_REMOTE) != EPKG_OK)
goto cleanup;
/* Initialize the remote remote */
if (pkgdb_remote_init(db, reponame) != EPKG_OK)
goto cleanup;
ret = EPKG_OK;
cleanup:
if (db)
pkgdb_close(db);
return (ret);
}
示例12: convert_from_old
static int
convert_from_old(const char *pkg_add_dbdir, bool dry_run)
{
DIR *d;
struct dirent *dp;
struct pkg *p = NULL;
char path[MAXPATHLEN];
struct pkgdb *db = NULL;
if ((d = opendir(pkg_add_dbdir)) == NULL)
err(EX_NOINPUT, "%s", pkg_add_dbdir);
if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
return (EX_IOERR);
}
while ((dp = readdir(d)) != NULL) {
if (dp->d_type == DT_DIR) {
if (strcmp(dp->d_name, ".") == 0 ||
strcmp(dp->d_name, "..") == 0)
continue;
if (p == NULL) {
if (pkg_new(&p, PKG_OLD_FILE) != EPKG_OK)
err(EX_OSERR, "malloc");
} else
pkg_reset(p, PKG_OLD_FILE);
printf("Converting %s...\n", dp->d_name);
snprintf(path, MAXPATHLEN, "%s/%s", pkg_add_dbdir, dp->d_name);
if (pkg_old_load_from_path(p, path) != EPKG_OK) {
fprintf(stderr, "Skipping invalid package: %s\n", path);
continue;
}
pkg_from_old(p);
if (!dry_run)
pkgdb_register_ports(db, p);
}
}
pkg_free(p);
pkgdb_close(db);
return (EX_OK);
}
示例13: exec_backup
int
exec_backup(int argc, char **argv)
{
struct pkgdb *db = NULL;
char *dest = NULL;
if (argc < 2 || argc > 3 || argv[1][0] != '-') {
usage_backup();
return (EX_USAGE);
}
if (argc == 3)
dest = argv[2];
if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
return (EX_IOERR);
if (argv[1][1] == 'd') {
if (isatty(fileno(stdin)))
printf("Dumping database...\n");
if (pkgdb_dump(db, dest) == EPKG_FATAL)
return (EX_IOERR);
if (isatty(fileno(stdin)))
printf("done\n");
}
if (argv[1][1] == 'r') {
if (isatty(fileno(stdin)))
printf("Restoring database...\n");
if (pkgdb_load(db, dest) == EPKG_FATAL)
return (EX_IOERR);
if (isatty(fileno(stdin)))
printf("done\n");
}
pkgdb_close(db);
return (EX_OK);
}
示例14: main
int
main(int argc, char **argv)
{
struct pkgdb *db;
int err;
if (argc != 2) {
fprintf(stderr, "usage: %s packagename\n", argv[0]);
return 1;
}
db = NULL;
err = pkg_init(NULL);
if (err == EPKG_OK)
err = getdb(&db);
else
fprintf(stderr, "could not parse config file\n");
if (err == EPKG_OK) {
struct pkgdb_it *it;
it = pkgdb_query(db, argv[1], MATCH_EXACT);
if (it == NULL)
printf("no local matches!\n");
else handle_it(it);
it = pkgdb_rquery(db, argv[1], MATCH_EXACT, NULL);
if (it == NULL)
printf("no remote matches!\n");
else handle_it(it);
printf("shutting down\n");
pkgdb_it_free(it);
pkgdb_close(db);
pkg_shutdown();
printf("shutdown\n");
}
}
示例15: exec_query
int
exec_query(int argc, char **argv)
{
struct pkgdb *db = NULL;
struct pkgdb_it *it = NULL;
struct pkg *pkg = NULL;
char *pkgname = NULL;
int query_flags = PKG_LOAD_BASIC;
match_t match = MATCH_EXACT;
int ch;
int ret = EPKG_OK;
int retcode = EXIT_SUCCESS;
int i;
char multiline = 0;
while ((ch = getopt(argc, argv, "agxXf:")) != -1) {
switch (ch) {
case 'a':
match = MATCH_ALL;
break;
case 'g':
match = MATCH_GLOB;
break;
case 'x':
match = MATCH_REGEX;
break;
case 'X':
match = MATCH_EREGEX;
break;
case 'f':
pkgname = optarg;
break;
default:
usage_query();
return (EX_USAGE);
}
}
argc -= optind;
argv += optind;
if (argc == 0) {
usage_query();
return (EX_USAGE);
}
if ((argc == 1) ^ (match == MATCH_ALL) && pkgname == NULL) {
usage_query();
return (EX_USAGE);
}
if (analyse_query_string(argv[0], &query_flags, &multiline) != EPKG_OK)
return (EX_USAGE);
if (pkgname != NULL) {
if (pkg_open(&pkg, pkgname, NULL) != EPKG_OK) {
return (1);
}
print_query(pkg, argv[0], multiline);
pkg_free(pkg);
return (0);
}
if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
return (EX_IOERR);
if (match == MATCH_ALL) {
if ((it = pkgdb_query(db, NULL, match)) == NULL)
return (EX_IOERR);
while ((ret = pkgdb_it_next(it, &pkg, query_flags)) == EPKG_OK)
print_query(pkg, argv[0], multiline);
if (ret != EPKG_END)
retcode = EX_SOFTWARE;
pkgdb_it_free(it);
} else {
for (i = 1; i < argc; i++) {
pkgname = argv[i];
if ((it = pkgdb_query(db, pkgname, match)) == NULL)
return (EX_IOERR);
while ((ret = pkgdb_it_next(it, &pkg, query_flags)) == EPKG_OK)
print_query(pkg, argv[0], multiline);
if (ret != EPKG_END) {
retcode = EX_SOFTWARE;
break;
}
pkgdb_it_free(it);
}
}
pkg_free(pkg);
pkgdb_close(db);
//.........这里部分代码省略.........