static alpm_list_t *expac_search_local(expac_t *expac, alpm_list_t *targets) { alpm_list_t *dblist, *r; dblist = alpm_list_add(NULL, alpm_get_localdb(expac->alpm)); r = resolve_targets(dblist, targets); alpm_list_free(dblist); return r; }
static time_t results_installdate (const results_t *r) { const char *r_name; alpm_pkg_t *pkg = NULL; time_t idate=0; if (r->type==R_AUR_PKG) return 0; r_name = results_name (r); pkg = alpm_db_get_pkg(alpm_get_localdb(config.handle), r_name); if (pkg) idate = alpm_pkg_get_installdate(pkg); return idate; }
static time_t results_installdate (const results_t *r) { if (!r || r->type == R_AUR_PKG) { return 0; } time_t idate = 0; const char *r_name = results_name (r); alpm_pkg_t *pkg = alpm_db_get_pkg (alpm_get_localdb(config.handle), r_name); if (pkg) { idate = alpm_pkg_get_installdate (pkg); } return idate; }
static alpm_handle_t *alpm_init(void) { alpm_handle_t *alpm = NULL; enum _alpm_errno_t alpm_errno = 0; FILE *fp; char line[PATH_MAX]; char *ptr, *section = NULL; alpm = alpm_initialize("/", "/var/lib/pacman", &alpm_errno); if (!alpm) { alpm_strerror(alpm_errno); return NULL; } db_local = alpm_get_localdb(alpm); fp = fopen("/etc/pacman.conf", "r"); if (!fp) { perror("fopen: /etc/pacman.conf"); return alpm; } while (fgets(line, PATH_MAX, fp)) { strtrim(line); if (strlen(line) == 0 || line[0] == '#') { continue; } if ((ptr = strchr(line, '#'))) { *ptr = '\0'; } if (line[0] == '[' && line[strlen(line) - 1] == ']') { ptr = &line[1]; if (section) { free(section); } section = strdup(ptr); section[strlen(section) - 1] = '\0'; if (strcmp(section, "options") != 0) { alpm_register_syncdb(alpm, section, 0); } } } free(section); fclose(fp); return alpm; }
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 char *make_optstring(alpm_depend_t *optdep) { char *optstring = alpm_dep_compute_string(optdep); char *status = NULL; if(alpm_db_get_pkg(alpm_get_localdb(config->handle), optdep->name)) { status = _(" [installed]"); } else if(alpm_pkg_find(alpm_trans_get_add(config->handle), optdep->name)) { status = _(" [pending]"); } if(status) { optstring = realloc(optstring, strlen(optstring) + strlen(status) + 1); strcpy(optstring + strlen(optstring), status); } return optstring; }
/** * call-seq: * local_db() → a_database * * Returns the database of locally installed packages. * An instance of Database. */ static VALUE local_db(VALUE self) { alpm_handle_t* p_alpm = NULL; alpm_db_t* p_db = NULL; VALUE obj; Data_Get_Struct(self, alpm_handle_t, p_alpm); p_db = alpm_get_localdb(p_alpm); if (!p_db) { rb_raise(rb_eAlpm_Error, "Failed to retrieve local DB from libalpm."); return Qnil; } obj = Data_Wrap_Struct(rb_cAlpm_Database, NULL, NULL, p_db); rb_iv_set(obj, "@alpm", self); return obj; }
/** Turn a optdepends list into a text list. * @param optdeps a list with items of type alpm_depend_t */ static void optdeplist_display(alpm_pkg_t *pkg, unsigned short cols) { alpm_list_t *i, *text = NULL; for(i = alpm_pkg_get_optdepends(pkg); i; i = alpm_list_next(i)) { alpm_depend_t *optdep = i->data; char *depstring = alpm_dep_compute_string(optdep); if(alpm_pkg_get_origin(pkg) == ALPM_PKG_FROM_LOCALDB) { if(alpm_db_get_pkg(alpm_get_localdb(config->handle), optdep->name)) { const char *installed = _(" [installed]"); depstring = realloc(depstring, strlen(depstring) + strlen(installed) + 1); strcpy(depstring + strlen(depstring), installed); } } text = alpm_list_add(text, depstring); } list_display_linebreak(_("Optional Deps :"), text, cols); FREELIST(text); }
alpm_pkg_t *pu_find_pkgspec(alpm_handle_t *handle, const char *pkgspec) { char *c; if(strstr(pkgspec, "://")) { alpm_pkg_t *pkg; alpm_siglevel_t sl = strncmp(pkgspec, "file://", 7) == 0 ? alpm_option_get_local_file_siglevel(handle) : alpm_option_get_remote_file_siglevel(handle); char *path = alpm_fetch_pkgurl(handle, pkgspec); int err = alpm_pkg_load(handle, path ? path : pkgspec, 1, sl, &pkg); free(path); if(!err) { return pkg; } } else if((c = strchr(pkgspec, '/'))) { alpm_db_t *db = NULL; size_t dblen = c - pkgspec; if(dblen == strlen("local") && memcmp(pkgspec, "local", dblen) == 0) { db = alpm_get_localdb(handle); } else { alpm_list_t *i; for(i = alpm_get_syncdbs(handle); i; i = i->next) { const char *dbname = alpm_db_get_name(i->data); if(dblen == strlen(dbname) && strncmp(pkgspec, dbname, dblen) == 0) { db = i->data; break; } } } if(!db) { return NULL; } else { return alpm_db_get_pkg(db, c + 1); } } return NULL; }
static gboolean pk_alpm_initialize (PkBackend *backend, GError **error) { PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend); priv->alpm = pk_alpm_configure (backend, PK_BACKEND_CONFIG_FILE, error); if (priv->alpm == NULL) { g_prefix_error (error, "using %s: ", PK_BACKEND_CONFIG_FILE); return FALSE; } alpm_option_set_logcb (priv->alpm, pk_alpm_logcb); priv->localdb = alpm_get_localdb (priv->alpm); if (priv->localdb == NULL) { alpm_errno_t errno = alpm_errno (priv->alpm); g_set_error (error, PK_ALPM_ERROR, errno, "[%s]: %s", "local", alpm_strerror (errno)); } return TRUE; }
static gboolean pk_backend_initialize_alpm (PkBackend *self, GError **error) { g_return_val_if_fail (self != NULL, FALSE); pk_backend_configure_environment (self); alpm = pk_backend_configure (PK_BACKEND_CONFIG_FILE, error); if (alpm == NULL) { return FALSE; } backend = self; alpm_option_set_logcb (alpm, pk_backend_logcb); localdb = alpm_get_localdb (alpm); if (localdb == NULL) { alpm_errno_t errno = alpm_errno (alpm); g_set_error (error, ALPM_ERROR, errno, "[%s]: %s", "local", alpm_strerror (errno)); } return TRUE; }
int main (int argc, char **argv) { int ret=0, i; int need=0, given=0, cycle_db=0, db_order=0; alpm_list_t *t; struct sigaction a; init_config (argv[0]); a.sa_handler = handler; sigemptyset(&a.sa_mask); a.sa_flags = 0; sigaction(SIGINT, &a, NULL); sigaction(SIGTERM, &a, NULL); int opt; int opt_index=0; static struct option opts[] = { {"query", no_argument, 0, 'Q'}, {"sync", no_argument, 0, 'S'}, {"dbpath", required_argument, 0, 'b'}, {"deps", no_argument, 0, 'd'}, {"explicit", no_argument, 0, 'e'}, {"groups", no_argument, 0, 'g'}, {"help", no_argument, 0, 'h'}, {"info", no_argument, 0, 'i'}, {"list", no_argument, 0, 'l'}, {"foreign", no_argument, 0, 'm'}, {"file", no_argument, 0, 'p'}, {"quiet", no_argument, 0, 'q'}, {"root", required_argument, 0, 'r'}, {"search", no_argument, 0, 's'}, {"unrequired", no_argument, 0, 't'}, {"upgrades", no_argument, 0, 'u'}, {"config", required_argument, 0, 'c'}, {"just-one", no_argument, 0, '1'}, {"aur", no_argument, 0, 'A'}, {"escape", no_argument, 0, 'x'}, {"format", required_argument, 0, 'f'}, {"list-repo", required_argument, 0, 'L'}, {"query-type", required_argument, 0, 1000}, {"csep", required_argument, 0, 1001}, {"delimiter", required_argument, 0, 1001}, {"sort", required_argument, 0, 1002}, {"nocolor", no_argument, 0, 1003}, {"number", no_argument, 0, 1004}, {"get-res", no_argument, 0, 1005}, {"show-size", no_argument, 0, 1006}, {"aur-url", required_argument, 0, 1007}, {"insecure", no_argument, 0, 1008}, {"qdepends", no_argument, 0, 1009}, {"qconflicts", no_argument, 0, 1010}, {"qprovides", no_argument, 0, 1011}, {"qreplaces", no_argument, 0, 1012}, {"qrequires", no_argument, 0, 1013}, {"color", no_argument, 0, 1014}, {"version", no_argument, 0, 'v'}, {0, 0, 0, 0} }; while ((opt = getopt_long (argc, argv, "1Ac:b:def:ghiLlmpQqr:Sstuvx", opts, &opt_index)) != -1) { switch (opt) { case '1': config.just_one = 1; break; case 'A': if (config.aur) break; config.aur = ++db_order; given |= N_DB; break; case 'c': FREE (config.configfile); config.configfile = strndup (optarg, PATH_MAX); break; case 'b': FREE (config.dbpath); config.dbpath = strndup (optarg, PATH_MAX); break; case 'd': config.filter |= F_DEPS; break; case 'e': config.filter |= F_EXPLICIT; break; case 'x': config.escape = 1; break; case 'f': config.custom_out = 1; strncpy (config.format_out, optarg, PATH_MAX); format_str (config.format_out); break; case 'g': if (config.op) break; config.op = OP_LIST_GROUP; config.filter |= F_GROUP; cycle_db = 1; break; case 'i': if (config.op) { if (config.op == OP_INFO) config.op = OP_INFO_P; break; } config.op = OP_INFO; need |= N_TARGET | N_DB; break; case 'L': config.list = 1; break; case 'l': if (config.op) break; config.op = OP_LIST_REPO; need |= N_DB; cycle_db = 1; break; case 'm': config.filter |= F_FOREIGN; break; case 'p': config.is_file = 1; need |= N_TARGET; break; case 'Q': if (config.db_local) break; config.db_local = ++db_order; given |= N_DB; break; case 'q': config.quiet = 1; break; case 'r': FREE (config.rootdir); config.rootdir = strndup (optarg, PATH_MAX); break; case 's': if (config.op) break; config.op = OP_SEARCH; need |= N_DB; cycle_db = 1; break; case 'S': if (config.db_sync) break; config.db_sync = ++db_order; given |= N_DB; break; case 't': config.filter |= F_UNREQUIRED; break; case 1000: /* --query-type */ if (config.op) break; config.op = OP_QUERY; if (strcmp (optarg, "depends")==0) config.query = OP_Q_DEPENDS; else if (strcmp (optarg, "conflicts")==0) config.query = OP_Q_CONFLICTS; else if (strcmp (optarg, "provides")==0) config.query = OP_Q_PROVIDES; else if (strcmp (optarg, "replaces")==0) config.query = OP_Q_REPLACES; need |= N_TARGET | N_DB; break; case 1009: /* --qdepends */ SETQUERY (OP_Q_DEPENDS); break; case 1010: /* --qconflicts */ SETQUERY (OP_Q_CONFLICTS); break; case 1011: /* --qprovides */ SETQUERY (OP_Q_PROVIDES); break; case 1012: /* --qreplaces */ SETQUERY (OP_Q_REPLACES); break; case 1013: /* --qrequires */ SETQUERY (OP_Q_REQUIRES); break; case 1001: /* --delimiter */ strncpy (config.delimiter, optarg, SEP_LEN); format_str (config.delimiter); break; case 1002: /* --sort */ config.sort = optarg[0]; break; case 1003: /* --nocolor */ config.colors=0; break; case 1004: /* --number */ config.numbering = 1; break; case 1005: /* --get-res */ if (dup2(FD_RES, FD_RES) == FD_RES) config.get_res = 1; break; case 1006: /* --show-size */ config.show_size = 1; break; case 1007: /* --aur-url */ FREE (config.aur_url); config.aur_url = strdup (optarg); break; case 1008: /* --insecure */ config.insecure = 1; break; case 1014: /* --color */ config.colors=1; break; case 'u': config.filter |= F_UPGRADES; break; case 'v': version(); break; case 'h': usage (0); break; default: /* '?' */ usage (1); } } if (config.list) { /* -L displays respository list and exits. */ alpm_list_t *dbs = get_db_sync (); if (dbs) { for(t = dbs; t; t = alpm_list_next(t)) printf ("%s\n", (char *)t->data); FREELIST (dbs); } cleanup (0); } if (!config.custom_out) { if (config.colors) color_init(); #if defined(HAVE_GETTEXT) && defined(ENABLE_NLS) /* TODO: specific package-query locale ? */ setlocale (LC_ALL, ""); bindtextdomain ("yaourt", LOCALEDIR); textdomain ("yaourt"); #endif } if ((need & N_DB) && !(given & N_DB)) { fprintf(stderr, "search or information must have database target (-{Q,S,A}).\n"); exit(1); } for (i = optind; i < argc; i++) { if (!config.just_one || !alpm_list_find_str (targets, argv[i])) targets = alpm_list_add(targets, strdup(argv[i])); } if (i!=optind) { given |= N_TARGET; } if ((need & N_TARGET) && !(given & N_TARGET)) { fprintf(stderr, "no targets specified.\n"); usage(1); } if (targets == NULL) { if (config.op == OP_SEARCH) config.op = OP_LIST_REPO_S; } else if (!config.op && (given & N_DB)) /* Show info by default */ config.op = OP_INFO; // init_db_sync initializes alpm after parsing [options] if (!init_db_sync ()) cleanup(1); if (config.is_file) { for(t = targets; t; t = alpm_list_next(t)) { alpm_pkg_t *pkg=NULL; const char *filename = t->data; if (alpm_pkg_load (config.handle, filename, 0, ALPM_SIG_USE_DEFAULT, &pkg)!=0 || pkg==NULL) { fprintf(stderr, "unable to read %s.\n", filename); continue; } print_package (filename, pkg, alpm_pkg_get_str); ret++; } cleanup(!ret); } if (cycle_db || targets) { for (i=1; i<=db_order && (cycle_db || targets); i++) { /*printf ("%d, aur %d, local %d, sync %d\n", i, config.aur, config.db_local, config.db_sync);*/ if (config.db_sync == i) { for(t = alpm_get_syncdbs(config.handle); t; t = alpm_list_next(t)) ret += deal_db (t->data); if (!ret && config.op == OP_INFO_P) { config.op = OP_QUERY; config.query = OP_Q_PROVIDES; for(t = alpm_get_syncdbs(config.handle); t; t = alpm_list_next(t)) ret += deal_db (t->data); config.op = OP_INFO_P; } } else if (config.db_local == i) ret += deal_db (alpm_get_localdb(config.handle)); else if (config.aur == i) switch (config.op) { case OP_INFO: case OP_INFO_P: ret += aur_info (&targets); break; case OP_SEARCH: ret += aur_search (targets); break; default: break; } } } else if (!config.aur && config.db_local) ret += alpm_search_local (config.filter, NULL, NULL); else if (config.aur && !(given & N_TARGET)) { if (config.filter & F_FOREIGN) { /* -Am */ config.aur_foreign = 1; config.just_one = 1; alpm_search_local (config.filter, "%n", &targets); ret += aur_info (&targets); if (config.db_local) /* -AQm */ ret += search_pkg_by_name (alpm_get_localdb(config.handle), &targets); } else if (config.filter & F_UPGRADES) { /* -Au */ config.aur_upgrades = 1; if (config.db_local) /* -AQu */ ret += alpm_search_local (config.filter, NULL, NULL); alpm_search_local (F_FOREIGN | (config.filter & ~F_UPGRADES), "%n>%v", &targets); ret += aur_info (&targets); } } show_results(); /* Some cleanups */ cleanup(!ret); return 0; }
static PyObject* pyalpm_get_localdb(PyObject *self, PyObject *dummy) { alpm_handle_t *handle = ALPM_HANDLE(self); return pyalpm_db_from_pmdb(alpm_get_localdb(handle)); }
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; }
/** * 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[]) { int freelist = 0, ret = 0; alpm_errno_t err; const char *target_name; alpm_pkg_t *pkg; alpm_list_t *dblist = NULL; if(parse_options(argc, argv) != 0) { usage(); ret = 1; goto finish; } handle = alpm_initialize(ROOTDIR, dbpath, &err); if(!handle) { fprintf(stderr, "error: cannot initialize alpm: %s\n", alpm_strerror(err)); ret = 1; goto finish; } if(searchsyncs) { if(register_syncs() != 0) { ret = 1; goto finish; } dblist = alpm_get_syncdbs(handle); } else { dblist = alpm_list_add(dblist, alpm_get_localdb(handle)); freelist = 1; } /* we only care about the first non option arg for walking */ target_name = argv[optind]; pkg = alpm_find_dbs_satisfier(handle, dblist, target_name); if(!pkg) { fprintf(stderr, "error: package '%s' not found\n", target_name); ret = 1; goto finish; } print_start(alpm_pkg_get_name(pkg), target_name); tdepth d = { NULL, NULL, 1 }; walk_deps(dblist, pkg, &d, reverse); print_end(); if(freelist) { alpm_list_free(dblist); } finish: cleanup(); return ret; }