/* search the local database for a matching package */ static int query_search(alpm_list_t *targets) { alpm_list_t *i, *searchlist; int freelist; alpm_db_t *db_local = alpm_option_get_localdb(config->handle); /* if we have a targets list, search for packages matching it */ if(targets) { searchlist = alpm_db_search(db_local, targets); freelist = 1; } else { searchlist = alpm_db_get_pkgcache(db_local); freelist = 0; } if(searchlist == NULL) { return 1; } for(i = searchlist; i; i = alpm_list_next(i)) { alpm_list_t *grp; alpm_pkg_t *pkg = alpm_list_getdata(i); if(!config->quiet) { printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); } else { printf("%s", alpm_pkg_get_name(pkg)); } if(!config->quiet) { if((grp = alpm_pkg_get_groups(pkg)) != NULL) { alpm_list_t *k; printf(" ("); for(k = grp; k; k = alpm_list_next(k)) { const char *group = alpm_list_getdata(k); printf("%s", group); if(alpm_list_next(k)) { /* only print a spacer if there are more groups */ printf(" "); } } printf(")"); } /* we need a newline and initial indent first */ printf("\n "); indentprint(alpm_pkg_get_desc(pkg), 4); } printf("\n"); } /* we only want to free if the list was a search list */ if(freelist) { alpm_list_free(searchlist); } return 0; }
/** * @brief Modify the 'local' package database. * * @param targets a list of packages (as strings) to modify * * @return 0 on success, 1 on failure */ int pacman_database(alpm_list_t *targets) { alpm_list_t *i; alpm_db_t *db_local; int retval = 0; alpm_pkgreason_t reason; if(targets == NULL) { pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n")); return 1; } if(config->flags & ALPM_TRANS_FLAG_ALLDEPS) { /* --asdeps */ reason = ALPM_PKG_REASON_DEPEND; } else if(config->flags & ALPM_TRANS_FLAG_ALLEXPLICIT) { /* --asexplicit */ reason = ALPM_PKG_REASON_EXPLICIT; } else { pm_printf(ALPM_LOG_ERROR, _("no install reason specified (use -h for help)\n")); return 1; } /* Lock database */ if(trans_init(0, 0) == -1) { return 1; } db_local = alpm_option_get_localdb(config->handle); for(i = targets; i; i = alpm_list_next(i)) { char *pkgname = i->data; alpm_pkg_t *pkg = alpm_db_get_pkg(db_local, pkgname); if(!pkg || alpm_db_set_pkgreason(config->handle, pkg, reason)) { pm_printf(ALPM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"), pkgname, alpm_strerror(alpm_errno(config->handle))); retval = 1; } else { if(reason == ALPM_PKG_REASON_DEPEND) { printf(_("%s: install reason has been set to 'installed as dependency'\n"), pkgname); } else { printf(_("%s: install reason has been set to 'explicitly installed'\n"), pkgname); } } } /* Unlock database */ if(trans_release() == -1) { return 1; } return retval; }
int pacman_deptest(alpm_list_t *targets) { alpm_list_t *i; alpm_list_t *deps = alpm_deptest(alpm_option_get_localdb(), targets); if(deps == NULL) { return(0); } for(i = deps; i; i = alpm_list_next(i)) { const char *dep; dep = alpm_list_getdata(i); printf("%s\n", dep); } alpm_list_free(deps); return(127); }
static int query_group(alpm_list_t *targets) { alpm_list_t *i, *j; char *grpname = NULL; int ret = 0; alpm_db_t *db_local = alpm_option_get_localdb(config->handle); if(targets == NULL) { for(j = alpm_db_get_groupcache(db_local); j; j = alpm_list_next(j)) { alpm_group_t *grp = alpm_list_getdata(j); const alpm_list_t *p; for(p = grp->packages; p; p = alpm_list_next(p)) { alpm_pkg_t *pkg = alpm_list_getdata(p); printf("%s %s\n", grp->name, alpm_pkg_get_name(pkg)); } } } else { for(i = targets; i; i = alpm_list_next(i)) { alpm_group_t *grp; grpname = alpm_list_getdata(i); grp = alpm_db_readgroup(db_local, grpname); if(grp) { const alpm_list_t *p; for(p = grp->packages; p; p = alpm_list_next(p)) { if(!config->quiet) { printf("%s %s\n", grpname, alpm_pkg_get_name(alpm_list_getdata(p))); } else { printf("%s\n", alpm_pkg_get_name(alpm_list_getdata(p))); } } } else { pm_fprintf(stderr, ALPM_LOG_ERROR, _("group '%s' was not found\n"), grpname); ret++; } } } return ret; }
int powaur_query(alpm_list_t *targets) { alpm_db_t *localdb = alpm_option_get_localdb(config->handle); if (!localdb) { return error(PW_ERR_INIT_LOCALDB); } alpm_list_t *dblist = NULL; alpm_list_t *i, *j, *dbcache; alpm_pkg_t *pkg, *spkg; int ret = 0, found; /* -i and -s conflicting options */ if (config->op_q_info && config->op_q_search) { pw_fprintf(PW_LOG_ERROR, stderr, "-i (info) and -s (search) are " "mutually exclusive.\n"); return -1; } /* No targets */ if (targets == NULL) { dblist = alpm_list_add(dblist, localdb); if (config->op_q_info) { /* -Qi, detailed info */ ret = pacman_db_dump(PKG_FROM_LOCAL, DUMP_Q_INFO); } else if (config->op_q_search) { /* -Qs * repo/pkg ver (grp) * desc */ ret = pacman_db_dump(PKG_FROM_LOCAL, DUMP_Q_SEARCH); } else { /* -Q * repo/pkg ver (grp) */ ret = pacman_db_dump(PKG_FROM_LOCAL, DUMP_Q); } alpm_list_free(dblist); return ret; } if (config->op_q_info) { ret = query_info(localdb, targets); } else if (config->op_q_search) { ret = query_search(localdb, targets->data); } else { /* Plain -Q */ alpm_list_t *sdbs = alpm_option_get_syncdbs(config->handle); dbcache = alpm_db_get_pkgcache(localdb); for (i = targets; i; i = i->next) { found = 0; for (j = dbcache; j; j = j->next) { pkg = j->data; if (!strcmp(i->data, alpm_pkg_get_name(pkg))) { print_pkg_pretty(sdbs, pkg, DUMP_Q); found = 1; break; } } if (!found) { printf("package \"%s\" not found\n", i->data); ret = -1; } } } return ret; }
/* Dumps info from dbs and returns. */ int pacman_db_dump(enum pkgfrom_t from, enum dumplvl_t lvl) { int cnt = 0; alpm_list_t *i, *j, *dbs, *syncdbs; const char *repo; pmdb_t *localdb, *db; pmpkg_t *pkg; pmdepend_t *dep; switch (lvl) { case DUMP_Q: case DUMP_Q_SEARCH: case DUMP_Q_INFO: localdb = alpm_option_get_localdb(); syncdbs = alpm_option_get_syncdbs(); break; case DUMP_S_SEARCH: case DUMP_S_INFO: dbs = alpm_option_get_syncdbs(); break; } if (lvl == DUMP_S_SEARCH || lvl == DUMP_S_INFO) { goto dump_sync; } /* -Qi */ if (lvl == DUMP_Q_INFO) { for (i = alpm_db_get_pkgcache(localdb); i; i = i->next) { pacman_pkgdump(i->data, PKG_FROM_LOCAL); } } else { /* plain -Q and -Qs */ for (j = alpm_db_get_pkgcache(localdb); j; j = j->next) { pkg = j->data; print_pkg_pretty(syncdbs, pkg, lvl); } } goto done; dump_sync: /* -S */ for (i = dbs; i; i = i->next) { db = i->data; for (j = alpm_db_get_pkgcache(db); j; j = j->next) { if (cnt++) { printf("\n"); } pkg = j->data; if (lvl == DUMP_S_INFO) { pacman_pkgdump(pkg, from); } else { /* -Ss */ print_pkg_pretty(dbs, pkg, lvl); } } } done: if (lvl != DUMP_Q && lvl != DUMP_Q_SEARCH) { printf("\n"); } return 0; }
static PyObject* pyalpm_get_localdb(PyObject *self, PyObject *dummy) { alpm_handle_t *handle = ALPM_HANDLE(self); return pyalpm_db_from_pmdb(alpm_option_get_localdb(handle)); }
/** * pacman_manager_get_local_database: * @manager: A #PacmanManager. * * Gets the local database. * * Returns: A #PacmanDatabase, or %NULL if no local database is registered. */ PacmanDatabase *pacman_manager_get_local_database (PacmanManager *manager) { g_return_val_if_fail (manager != NULL, NULL); return alpm_option_get_localdb (); }
int pacman_query(alpm_list_t *targets) { int ret = 0; int match = 0; alpm_list_t *i; alpm_pkg_t *pkg = NULL; alpm_db_t *db_local; /* First: operations that do not require targets */ /* search for a package */ if(config->op_q_search) { ret = query_search(targets); return ret; } /* looking for groups */ if(config->group) { ret = query_group(targets); return ret; } if(config->op_q_foreign || config->op_q_upgrade) { if(check_syncdbs(1, 1)) { return 1; } } db_local = alpm_option_get_localdb(config->handle); /* operations on all packages in the local DB * valid: no-op (plain -Q), list, info, check * invalid: isfile, owns */ if(targets == NULL) { if(config->op_q_isfile || config->op_q_owns) { pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n")); return 1; } for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) { pkg = alpm_list_getdata(i); if(filter(pkg)) { int value = display(pkg); if(value != 0) { ret = 1; } match = 1; } } if(!match) { ret = 1; } return ret; } /* Second: operations that require target(s) */ /* determine the owner of a file */ if(config->op_q_owns) { ret = query_fileowner(targets); return ret; } /* operations on named packages in the local DB * valid: no-op (plain -Q), list, info, check */ for(i = targets; i; i = alpm_list_next(i)) { char *strname = alpm_list_getdata(i); if(config->op_q_isfile) { alpm_pkg_load(config->handle, strname, 1, 0, &pkg); } else { pkg = alpm_db_get_pkg(db_local, strname); } if(pkg == NULL) { switch(alpm_errno(config->handle)) { case ALPM_ERR_PKG_NOT_FOUND: pm_fprintf(stderr, ALPM_LOG_ERROR, _("package '%s' was not found\n"), strname); if(!config->op_q_isfile && access(strname, R_OK) == 0) { pm_fprintf(stderr, ALPM_LOG_WARNING, _("'%s' is a file, you might want to use %s.\n"), strname, "-p/--file"); } break; default: pm_fprintf(stderr, ALPM_LOG_ERROR, _("could not load package '%s': %s\n"), strname, alpm_strerror(alpm_errno(config->handle))); break; } ret = 1; continue; } if(filter(pkg)) { int value = display(pkg); if(value != 0) { ret = 1; } match = 1; } if(config->op_q_isfile) { alpm_pkg_free(pkg); pkg = NULL; } } if(!match) { ret = 1; } return ret; }
static int query_fileowner(alpm_list_t *targets) { int ret = 0; char path[PATH_MAX]; const char *root; size_t rootlen; alpm_list_t *t; alpm_db_t *db_local; /* This code is here for safety only */ if(targets == NULL) { pm_fprintf(stderr, ALPM_LOG_ERROR, _("no file was specified for --owns\n")); return 1; } /* Set up our root path buffer. We only need to copy the location of root in * once, then we can just overwrite whatever file was there on the previous * iteration. */ root = alpm_option_get_root(config->handle); rootlen = strlen(root); if(rootlen + 1 > PATH_MAX) { /* we are in trouble here */ pm_fprintf(stderr, ALPM_LOG_ERROR, _("path too long: %s%s\n"), root, ""); return 1; } strcpy(path, root); db_local = alpm_option_get_localdb(config->handle); for(t = targets; t; t = alpm_list_next(t)) { char *filename, *dname, *rpath; const char *bname; struct stat buf; alpm_list_t *i; int found = 0; filename = strdup(alpm_list_getdata(t)); if(lstat(filename, &buf) == -1) { /* if it is not a path but a program name, then check in PATH */ if(strchr(filename, '/') == NULL) { if(search_path(&filename, &buf) == -1) { pm_fprintf(stderr, ALPM_LOG_ERROR, _("failed to find '%s' in PATH: %s\n"), filename, strerror(errno)); ret++; free(filename); continue; } } else { pm_fprintf(stderr, ALPM_LOG_ERROR, _("failed to read file '%s': %s\n"), filename, strerror(errno)); ret++; free(filename); continue; } } if(S_ISDIR(buf.st_mode)) { pm_fprintf(stderr, ALPM_LOG_ERROR, _("cannot determine ownership of directory '%s'\n"), filename); ret++; free(filename); continue; } bname = mbasename(filename); dname = mdirname(filename); /* for files in '/', there is no directory name to match */ if(strcmp(dname, "") == 0) { rpath = NULL; } else { rpath = resolve_path(dname); if(!rpath) { pm_fprintf(stderr, ALPM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"), filename, strerror(errno)); free(filename); free(dname); free(rpath); ret++; continue; } } free(dname); for(i = alpm_db_get_pkgcache(db_local); i && !found; i = alpm_list_next(i)) { alpm_pkg_t *info = alpm_list_getdata(i); alpm_filelist_t *filelist = alpm_pkg_get_files(info); size_t j; for(j = 0; j < filelist->count; j++) { const alpm_file_t *file = filelist->files + j; char *ppath, *pdname; const char *pkgfile = file->name; /* avoid the costly resolve_path usage if the basenames don't match */ if(strcmp(mbasename(pkgfile), bname) != 0) { continue; } /* for files in '/', there is no directory name to match */ if(!rpath) { print_query_fileowner(filename, info); found = 1; continue; } if(rootlen + 1 + strlen(pkgfile) > PATH_MAX) { pm_fprintf(stderr, ALPM_LOG_ERROR, _("path too long: %s%s\n"), root, pkgfile); } /* concatenate our file and the root path */ strcpy(path + rootlen, pkgfile); pdname = mdirname(path); ppath = resolve_path(pdname); free(pdname); if(ppath && strcmp(ppath, rpath) == 0) { print_query_fileowner(filename, info); found = 1; } free(ppath); } } if(!found) { pm_fprintf(stderr, ALPM_LOG_ERROR, _("No package owns %s\n"), filename); ret++; } free(filename); free(rpath); } return ret; }
int pacman_query(alpm_list_t *targets) { int ret = 0; int match = 0; alpm_list_t *i; alpm_pkg_t *pkg = NULL; alpm_db_t *db_local; /* First: operations that do not require targets */ /* search for a package */ if(config->op_q_search) { ret = query_search(targets); return ret; } /* looking for groups */ if(config->group) { ret = query_group(targets); return ret; } if(config->op_q_foreign || config->op_q_upgrade) { if(check_syncdbs(1, 1)) { return 1; } } db_local = alpm_option_get_localdb(config->handle); /* operations on all packages in the local DB * valid: no-op (plain -Q), list, info, check * invalid: isfile, owns */ if(targets == NULL) { if(config->op_q_isfile || config->op_q_owns) { pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n")); return 1; } for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) { pkg = alpm_list_getdata(i); if(filter(pkg)) { int value = display(pkg); if(value != 0) { ret = 1; } match = 1; } } if(!match) { ret = 1; } return ret; } /* Second: operations that require target(s) */ /* determine the owner of a file */ if(config->op_q_owns) { ret = query_fileowner(targets); return ret; } /* operations on named packages in the local DB * valid: no-op (plain -Q), list, info, check */ for(i = targets; i; i = alpm_list_next(i)) { char *strname = alpm_list_getdata(i); if(config->op_q_isfile) { alpm_pkg_load(config->handle, strname, 1, 0, &pkg); } else { pkg = alpm_db_get_pkg(db_local, strname); } if(pkg == NULL) { pm_fprintf(stderr, ALPM_LOG_ERROR, _("package \"%s\" not found\n"), strname); ret = 1; continue; } if(filter(pkg)) { int value = display(pkg); if(value != 0) { ret = 1; } match = 1; } if(config->op_q_isfile) { alpm_pkg_free(pkg); pkg = NULL; } } if(!match) { ret = 1; } return ret; }