static void pk_backend_search_db (PkBackendJob *job, alpm_db_t *db, MatchFunc match, const alpm_list_t *patterns) { PkBackend *backend = pk_backend_job_get_backend (job); PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend); const alpm_list_t *i, *j; g_return_if_fail (db != NULL); g_return_if_fail (match != NULL); /* emit packages that match all search terms */ for (i = alpm_db_get_pkgcache (db); i != NULL; i = i->next) { if (pk_backend_job_is_cancelled (job)) break; for (j = patterns; j != NULL; j = j->next) { if (!match (i->data, j->data)) break; } /* all search terms matched */ if (j == NULL) { if (db == priv->localdb) { pk_alpm_pkg_emit (job, i->data, PK_INFO_ENUM_INSTALLED); } else if (!pk_alpm_pkg_is_local (job, i->data)) { pk_alpm_pkg_emit (job, i->data, PK_INFO_ENUM_AVAILABLE); } } } }
static pmpkg_t * alpm_pkg_find_update (pmpkg_t *pkg, const alpm_list_t *dbs) { const gchar *name; const alpm_list_t *i; g_return_val_if_fail (pkg != NULL, NULL); name = alpm_pkg_get_name (pkg); for (; dbs != NULL; dbs = dbs->next) { pmpkg_t *update = alpm_db_get_pkg (dbs->data, name); if (update != NULL) { if (alpm_pkg_vercmp (alpm_pkg_get_version (update), alpm_pkg_get_version (pkg)) > 0) { return update; } else { return NULL; } } i = alpm_db_get_pkgcache (dbs->data); for (; i != NULL; i = i->next) { if (alpm_list_find_str (alpm_pkg_get_replaces (i->data), name) != NULL) { return i->data; } } } return NULL; }
int pacman_deptest(alpm_list_t *targets) { alpm_list_t *i; alpm_list_t *deps = NULL; alpm_db_t *localdb = alpm_get_localdb(config->handle); for(i = targets; i; i = alpm_list_next(i)) { char *target = i->data; if(!alpm_find_satisfier(alpm_db_get_pkgcache(localdb), target)) { deps = alpm_list_add(deps, target); } } if(deps == NULL) { return 0; } for(i = deps; i; i = alpm_list_next(i)) { const char *dep = i->data; printf("%s\n", dep); } alpm_list_free(deps); return 127; }
/* Returns a statically allocated string stating which db the pkg came from * @param sdbs sync dbs * @param pkgname package to search for * @param grp pointer to alpm_list_t * used to store the pkg's groups if any */ const char *which_db(alpm_list_t *sdbs, const char *pkgname, alpm_list_t **grp) { const char *repo = NULL; alpm_list_t *i, *k; pmpkg_t *spkg; for (i = sdbs; i && !repo; i = i->next) { for (k = alpm_db_get_pkgcache(i->data); k; k = k->next) { spkg = k->data; if (!strcmp(alpm_pkg_get_name(spkg), pkgname)) { repo = alpm_db_get_name(i->data); if (grp) { *grp = alpm_pkg_get_groups(spkg); } break; } } } if (!repo) { repo = LOCAL; } return repo; }
/* -Qs, only 1 target for now */ static int query_search(alpm_db_t *localdb, const char *pkgname) { int ret, found; const char *repo; alpm_list_t *i, *k, *dbcache, *groups; alpm_list_t *syncdbs; alpm_pkg_t *pkg; dbcache = alpm_db_get_pkgcache(localdb); syncdbs = alpm_option_get_syncdbs(config->handle); for (k = dbcache; k; k = k->next) { pkg = k->data; groups = NULL; if (!strcmp(pkgname, alpm_pkg_get_name(pkg))) { repo = which_db(syncdbs, pkgname, &groups); color_repo(repo); printf("%s%s %s%s", color.bold, pkgname, color.bgreen, alpm_pkg_get_version(pkg)); color_groups(groups); printf("%s %s\n", TAB, alpm_pkg_get_desc(pkg)); found = 1; } } return found ? 0: -1; }
static int files_list(alpm_list_t *syncs, alpm_list_t *targets) { alpm_list_t *i, *j; int ret = 0, found = 0; if(targets != NULL) { for(i = targets; i; i = alpm_list_next(i)) { char *targ = i->data; char *repo = NULL; char *c = strchr(targ, '/'); if(c) { if(! *(c + 1)) { pm_printf(ALPM_LOG_ERROR, _("invalid package: '%s'\n"), targ); ret += 1; continue; } repo = strndup(targ, c - targ); targ = c + 1; } for(j = syncs; j; j = alpm_list_next(j)) { alpm_pkg_t *pkg; alpm_db_t *db = j->data; if(repo) { if(strcmp(alpm_db_get_name(db), repo) != 0) { continue; } } if((pkg = alpm_db_get_pkg(db, targ)) != NULL) { found = 1; dump_file_list(pkg); break; } } if(!found) { targ = i->data; pm_printf(ALPM_LOG_ERROR, _("package '%s' was not found\n"), targ); ret += 1; } free(repo); } } else { for(i = syncs; i; i = alpm_list_next(i)) { alpm_db_t *db = i->data; for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) { alpm_pkg_t *pkg = j->data; dump_file_list(pkg); } } } return ret; }
/* 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; }
static alpm_list_t *all_packages(alpm_list_t *dbs) { alpm_list_t *i, *packages = NULL; for (i = dbs; i; i = i->next) { packages = alpm_list_join(packages, alpm_list_copy(alpm_db_get_pkgcache(i->data))); } return packages; }
static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) { int ret = 0; alpm_list_t *t; for(t = targets; t; t = alpm_list_next(t)) { char *filename = NULL, *f; int found = 0; alpm_list_t *s; size_t len; if((filename = strdup(t->data)) == NULL) { goto notfound; } len = strlen(filename); f = filename; while(len > 1 && f[0] == '/') { f = f + 1; len--; } for(s = syncs; s; s = alpm_list_next(s)) { alpm_list_t *p; alpm_db_t *repo = s->data; alpm_list_t *packages = alpm_db_get_pkgcache(repo); for(p = packages; p; p = alpm_list_next(p)) { alpm_pkg_t *pkg = p->data; alpm_filelist_t *files = alpm_pkg_get_files(pkg); if(alpm_filelist_contains(files, f)) { if(!config->quiet) { printf(_("%s is owned by %s/%s %s\n"), f, alpm_db_get_name(repo), alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); } else { printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg)); } found = 1; } } } free(filename); notfound: if(!found) { ret++; } } return 0; }
/* Convert a list of alpm_pkg_t * to a graph structure, * with a edge for each dependency. * Returns a list of vertices (one vertex = one package) * (used by alpm_sortbydeps) */ static alpm_list_t *dep_graph_init(alpm_handle_t *handle, alpm_list_t *targets, alpm_list_t *ignore) { alpm_list_t *i, *j; alpm_list_t *vertices = NULL; alpm_list_t *localpkgs = alpm_list_diff( alpm_db_get_pkgcache(handle->db_local), ignore, ptr_cmp); /* We create the vertices */ for(i = targets; i; i = i->next) { alpm_graph_t *vertex = _alpm_graph_new(); vertex->data = (void *)i->data; vertices = alpm_list_add(vertices, vertex); } /* We compute the edges */ for(i = vertices; i; i = i->next) { alpm_graph_t *vertex_i = i->data; alpm_pkg_t *p_i = vertex_i->data; /* TODO this should be somehow combined with alpm_checkdeps */ for(j = vertices; j; j = j->next) { alpm_graph_t *vertex_j = j->data; alpm_pkg_t *p_j = vertex_j->data; if(_alpm_pkg_depends_on(p_i, p_j)) { vertex_i->children = alpm_list_add(vertex_i->children, vertex_j); } } /* lazily add local packages to the dep graph so they don't * get resolved unnecessarily */ j = localpkgs; while(j) { alpm_list_t *next = j->next; if(_alpm_pkg_depends_on(p_i, j->data)) { alpm_graph_t *vertex_j = _alpm_graph_new(); vertex_j->data = (void *)j->data; vertices = alpm_list_add(vertices, vertex_j); vertex_i->children = alpm_list_add(vertex_i->children, vertex_j); localpkgs = alpm_list_remove_item(localpkgs, j); free(j); } j = next; } vertex_i->childptr = vertex_i->children; } alpm_list_free(localpkgs); return vertices; }
static int files_fileowner(alpm_list_t *syncs, alpm_list_t *targets) { int ret = 0; alpm_list_t *t; for(t = targets; t; t = alpm_list_next(t)) { char *filename = t->data; int found = 0; alpm_list_t *s; size_t len = strlen(filename); while(len > 1 && filename[0] == '/') { filename++; len--; } for(s = syncs; s; s = alpm_list_next(s)) { alpm_list_t *p; alpm_db_t *repo = s->data; alpm_list_t *packages = alpm_db_get_pkgcache(repo); for(p = packages; p; p = alpm_list_next(p)) { alpm_pkg_t *pkg = p->data; alpm_filelist_t *files = alpm_pkg_get_files(pkg); if(alpm_filelist_contains(files, filename)) { if(config->op_f_machinereadable) { print_line_machinereadable(repo, pkg, filename); } else if(!config->quiet) { const colstr_t *colstr = &config->colstr; printf(_("%s is owned by %s%s/%s%s %s%s\n"), filename, colstr->repo, alpm_db_get_name(repo), colstr->title, alpm_pkg_get_name(pkg), colstr->version, alpm_pkg_get_version(pkg)); } else { printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg)); } found = 1; } } } if(!found) { ret++; } } return 0; }
static gboolean pk_backend_get_updates_thread (PkBackend *self) { struct stat cache; time_t one_hour_ago; const alpm_list_t *i, *syncdbs; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (localdb != NULL, FALSE); time (&one_hour_ago); one_hour_ago -= 60 * 60; /* refresh databases if they are older than an hour */ if (g_stat (ALPM_CACHE_PATH, &cache) < 0 || cache.st_mtime < one_hour_ago) { GError *error = NULL; /* show updates even if the databases could not be updated */ if (!pk_backend_update_databases (self, 0, &error)) { g_warning ("%s", error->message); } } else { g_debug ("databases have been refreshed recently"); } /* find outdated and replacement packages */ syncdbs = alpm_option_get_syncdbs (); for (i = alpm_db_get_pkgcache (localdb); i != NULL; i = i->next) { pmpkg_t *upgrade = alpm_pkg_find_update (i->data, syncdbs); if (pk_backend_cancelled (self)) { break; } else if (upgrade != NULL) { PkInfoEnum info; if (alpm_pkg_is_ignorepkg (upgrade)) { info = PK_INFO_ENUM_BLOCKED; } else if (alpm_pkg_is_syncfirst (upgrade)) { info = PK_INFO_ENUM_IMPORTANT; } else { info = PK_INFO_ENUM_NORMAL; } pk_backend_pkg (self, upgrade, info); } } return pk_backend_finish (self, NULL); }
alpm_list_t *alpm_all_backups(int everything) /* {{{ */ { alpm_list_t *backups = NULL; const alpm_list_t *i; alpm_db_t *db = alpm_get_localdb(pmhandle); alpm_list_t *targets = cfg.targets ? alpm_db_search(db, cfg.targets) : alpm_db_get_pkgcache(db); for (i = targets; i; i = i->next) { alpm_list_t *pkg_backups = alpm_find_backups(i->data, everything); backups = alpm_list_join(backups, pkg_backups); } return backups; } /* }}} */
static void checkdbs(alpm_list_t *dbnames) { alpm_db_t *db = NULL; alpm_list_t *i; const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL; for(i = dbnames; i; i = alpm_list_next(i)) { const char *dbname = i->data; db = alpm_register_syncdb(handle, dbname, level); if(db == NULL) { fprintf(stderr, "error: could not register sync database '%s' (%s)\n", dbname, alpm_strerror(alpm_errno(handle))); continue; } checkpkgs(alpm_db_get_pkgcache(db)); } }
/* -Si, search inside sync dbs */ static alpm_pkg_t *search_syncdbs(alpm_list_t *dbs, const char *pkgname) { alpm_list_t *i, *j; alpm_db_t *sdb; alpm_pkg_t *spkg; for (i = dbs; i; i = i->next) { sdb = i->data; for (j = alpm_db_get_pkgcache(sdb); j; j = j->next) { spkg = j->data; if (!strcmp(pkgname, alpm_pkg_get_name(spkg))) { return spkg; } } } return NULL; }
static void pk_backend_search_db (PkBackendJob *job, alpm_db_t *db, MatchFunc match, const alpm_list_t *patterns, PkBitfield filters) { PkBackend *backend = pk_backend_job_get_backend (job); PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend); const alpm_list_t *i, *j; g_return_if_fail (db != NULL); g_return_if_fail (match != NULL); /* emit packages that match all search terms */ for (i = alpm_db_get_pkgcache (db); i != NULL; i = i->next) { if (pk_backend_job_is_cancelled (job)) break; for (j = patterns; j != NULL; j = j->next) { if (!match (i->data, j->data)) break; } /* not all search terms matched */ if (j != NULL) continue; /* want applications */ if (pk_bitfield_contain (filters, PK_FILTER_ENUM_APPLICATION) && !pk_alpm_search_is_application (i->data)) continue; /* don't want applications */ if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_APPLICATION) && pk_alpm_search_is_application (i->data)) continue; if (db == priv->localdb) { pk_alpm_pkg_emit (job, i->data, PK_INFO_ENUM_INSTALLED); } else if (!pk_alpm_pkg_is_local (job, i->data)) { pk_alpm_pkg_emit (job, i->data, PK_INFO_ENUM_AVAILABLE); } } }
/* -Qi */ static int query_info(alpm_db_t *localdb, alpm_list_t *targets) { int ret, hits, found, pkgcount; alpm_list_t *i, *k, *dbcache; alpm_pkg_t *pkg; ret = pkgcount = hits = found = 0; dbcache = alpm_db_get_pkgcache(localdb); for (i = targets; i; i = i->next, ++pkgcount) { found = 0; for (k = dbcache; k; k = k->next) { pkg = k->data; if (!strcmp(i->data, alpm_pkg_get_name(pkg))) { if (hits++) { printf("\n"); } found = 1; pacman_pkgdump(pkg, PKG_FROM_LOCAL); break; } } if (!found) { if (pkgcount) { printf("\n"); } ret = -1; pw_fprintf(PW_LOG_ERROR, stderr, "package %s not found\n", i->data); } } return ret; }
VALUE db_pkgs ( VALUE self ) { INITDBPTR; return alpmpkglist_to_ary( alpm_db_get_pkgcache( db )); }
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; }
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; }
static alpm_list_t * pk_backend_find_provider (PkBackend *self, alpm_list_t *pkgs, const gchar *depend, GError **error) { PkBitfield filters; gboolean recursive, skip_local, skip_remote; alpm_pkg_t *provider; alpm_list_t *pkgcache, *syncdbs; g_return_val_if_fail (self != NULL, pkgs); g_return_val_if_fail (depend != NULL, pkgs); g_return_val_if_fail (alpm != NULL, pkgs); g_return_val_if_fail (localdb != NULL, pkgs); recursive = pk_backend_get_bool (self, "recursive"); filters = pk_backend_get_uint (self, "filters"); skip_local = pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED); skip_remote = pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED); if (alpm_find_satisfier (pkgs, depend) != NULL) { return pkgs; } /* look for local dependencies */ pkgcache = alpm_db_get_pkgcache (localdb); provider = alpm_find_satisfier (pkgcache, depend); if (provider != NULL) { if (!skip_local) { pk_backend_pkg (self, provider, PK_INFO_ENUM_INSTALLED); /* assume later dependencies will also be local */ if (recursive) { pkgs = alpm_list_add (pkgs, provider); } } return pkgs; } /* look for remote dependencies */ syncdbs = alpm_get_syncdbs (alpm); provider = alpm_find_dbs_satisfier (alpm, syncdbs, depend); if (provider != NULL) { if (!skip_remote) { pk_backend_pkg (self, provider, PK_INFO_ENUM_AVAILABLE); } /* keep looking for local dependencies */ if (recursive) { pkgs = alpm_list_add (pkgs, provider); } } else { int code = ALPM_ERR_UNSATISFIED_DEPS; g_set_error (error, ALPM_ERROR, code, "%s: %s", depend, alpm_strerror (code)); } return pkgs; }
/* 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; }
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; }
/** * Display the details of a search. * @param db the database we're searching * @param targets the targets we're searching for * @param show_status show if the package is also in the local db */ int dump_pkg_search(alpm_db_t *db, alpm_list_t *targets, int show_status) { int freelist = 0; alpm_db_t *db_local; alpm_list_t *i, *searchlist; unsigned short cols; const colstr_t *colstr = &config->colstr; if(show_status) { db_local = alpm_get_localdb(config->handle); } /* if we have a targets list, search for packages matching it */ if(targets) { searchlist = alpm_db_search(db, targets); freelist = 1; } else { searchlist = alpm_db_get_pkgcache(db); freelist = 0; } if(searchlist == NULL) { return 1; } cols = getcols(fileno(stdout)); for(i = searchlist; i; i = alpm_list_next(i)) { alpm_list_t *grp; alpm_pkg_t *pkg = i->data; if(config->quiet) { fputs(alpm_pkg_get_name(pkg), stdout); } else { printf("%s%s/%s%s %s%s%s", colstr->repo, alpm_db_get_name(db), colstr->title, alpm_pkg_get_name(pkg), colstr->version, alpm_pkg_get_version(pkg), colstr->nocolor); if((grp = alpm_pkg_get_groups(pkg)) != NULL) { alpm_list_t *k; printf(" %s(", colstr->groups); for(k = grp; k; k = alpm_list_next(k)) { const char *group = k->data; fputs(group, stdout); if(alpm_list_next(k)) { /* only print a spacer if there are more groups */ putchar(' '); } } printf(")%s", colstr->nocolor); } if(show_status) { print_installed(db_local, pkg); } /* we need a newline and initial indent first */ fputs("\n ", stdout); indentprint(alpm_pkg_get_desc(pkg), 4, cols); } fputc('\n', stdout); } /* we only want to free if the list was a search list */ if(freelist) { alpm_list_free(searchlist); } return 0; }
int main(int argc, char **argv) { alpm_list_t *i; int ret = 0; if(!(config = parse_opts(argc, argv))) { ret = 1; goto cleanup; } if(checks == 0) { checks = CHECK_DEPENDS | CHECK_FILES; } if(!(handle = pu_initialize_handle_from_config(config))) { fprintf(stderr, "error: failed to initialize alpm.\n"); ret = 1; goto cleanup; } localdb = alpm_get_localdb(handle); pkgcache = alpm_db_get_pkgcache(localdb); for(; optind < argc; ++optind) { if(load_pkg(argv[optind]) == NULL) { ret = 1; } } if(!isatty(fileno(stdin)) && errno != EBADF) { char *buf = NULL; size_t len = 0; ssize_t read; while((read = getdelim(&buf, &len, isep, stdin)) != -1) { if(buf[read - 1] == isep) { buf[read - 1] = '\0'; } if(load_pkg(buf) == NULL) { ret = 1; } } free(buf); } if(ret) { goto cleanup; } if(packages == NULL) { packages = alpm_list_copy(pkgcache); recursive = 0; } else if(recursive) { /* load [opt-]depends */ alpm_list_t *i, *originals = alpm_list_copy(packages); for(i = originals; i; i = alpm_list_next(i)) { add_deps(i->data); } alpm_list_free(originals); } for(i = packages; i; i = alpm_list_next(i)) { int pkgerr = 0; #define RUNCHECK(t, b) if((checks & t) && b != 0) { pkgerr = ret = 1; } RUNCHECK(CHECK_DEPENDS, check_depends(i->data)); RUNCHECK(CHECK_OPT_DEPENDS, check_opt_depends(i->data)); RUNCHECK(CHECK_FILES, check_files(i->data)); RUNCHECK(CHECK_FILE_PROPERTIES, check_file_properties(i->data)); RUNCHECK(CHECK_MD5SUM, check_md5sum(i->data)); RUNCHECK(CHECK_SHA256SUM, check_sha256sum(i->data)); #undef RUNCHECK if(pkgerr && list_broken) { printf("%s\n", alpm_pkg_get_name(i->data)); } } cleanup: alpm_list_free(packages); alpm_release(handle); pu_config_free(config); return ret; }
static int files_search(alpm_list_t *syncs, alpm_list_t *targets, int regex) { int ret = 0; alpm_list_t *t; const colstr_t *colstr = &config->colstr; for(t = targets; t; t = alpm_list_next(t)) { char *targ = t->data; alpm_list_t *s; int found = 0; regex_t reg; if(regex) { if(regcomp(®, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) { /* TODO: error message */ goto notfound; } } for(s = syncs; s; s = alpm_list_next(s)) { alpm_list_t *p; alpm_db_t *repo = s->data; alpm_list_t *packages = alpm_db_get_pkgcache(repo); int m; for(p = packages; p; p = alpm_list_next(p)) { size_t f = 0; char* c; alpm_pkg_t *pkg = p->data; alpm_filelist_t *files = alpm_pkg_get_files(pkg); alpm_list_t *match = NULL; while(f < files->count) { c = strrchr(files->files[f].name, '/'); if(c && *(c + 1)) { if(regex) { m = regexec(®, (c + 1), 0, 0, 0); } else { m = strcmp(c + 1, targ); } if(m == 0) { match = alpm_list_add(match, files->files[f].name); found = 1; } } f++; } if(match != NULL) { if(config->op_f_machinereadable) { alpm_list_t *ml; for(ml = match; ml; ml = alpm_list_next(ml)) { char *filename = ml->data; print_line_machinereadable(repo, pkg, filename); } } else if(config->quiet) { printf("%s/%s\n", alpm_db_get_name(repo), alpm_pkg_get_name(pkg)); } else { alpm_list_t *ml; printf("%s%s/%s%s %s%s%s\n", colstr->repo, alpm_db_get_name(repo), colstr->title, alpm_pkg_get_name(pkg), colstr->version, alpm_pkg_get_version(pkg), colstr->nocolor); for(ml = match; ml; ml = alpm_list_next(ml)) { c = ml->data; printf(" %s\n", c); } } alpm_list_free(match); } } } if(regex) { regfree(®); } notfound: if(!found) { ret++; } } return 0; }
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; }