static gboolean disabled_repos_configure (GHashTable *table, GError **error) { const alpm_list_t *i; g_debug ("reading config from %s", PK_BACKEND_CONFIG_FILE); /* read configuration from pacman.conf file */ if (!pk_backend_configure (PK_BACKEND_CONFIG_FILE, error)) { return FALSE; } /* disable disabled repos */ for (i = alpm_option_get_syncdbs (); i != NULL;) { pmdb_t *db = (pmdb_t *) i->data; const gchar *repo = alpm_db_get_name (db); if (g_hash_table_lookup (table, repo) == NULL) { /* repo is not disabled */ i = i->next; continue; } if (alpm_db_unregister (db) < 0) { g_set_error (error, ALPM_ERROR, pm_errno, "[%s]: %s", repo, alpm_strerrorlast ()); return FALSE; } /* start again because the list gets invalidated */ i = alpm_option_get_syncdbs (); } return TRUE; }
/* -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 filter(alpm_pkg_t *pkg) { /* check if this package was explicitly installed */ if(config->op_q_explicit && alpm_pkg_get_reason(pkg) != ALPM_PKG_REASON_EXPLICIT) { return 0; } /* check if this package was installed as a dependency */ if(config->op_q_deps && alpm_pkg_get_reason(pkg) != ALPM_PKG_REASON_DEPEND) { return 0; } /* check if this pkg isn't in a sync DB */ if(config->op_q_foreign && !is_foreign(pkg)) { return 0; } /* check if this pkg is unrequired */ if(config->op_q_unrequired && !is_unrequired(pkg)) { return 0; } /* check if this pkg is outdated */ if(config->op_q_upgrade && (alpm_sync_newversion(pkg, alpm_option_get_syncdbs(config->handle)) == NULL)) { return 0; } return 1; }
static gboolean pk_backend_update_databases (PkBackend *self, gint force, GError **error) { alpm_cb_download dlcb; alpm_cb_totaldl totaldlcb; const alpm_list_t *i; g_return_val_if_fail (self != NULL, FALSE); if (!pk_backend_transaction_initialize (self, 0, error)) { return FALSE; } alpm_logaction ("synchronizing package lists\n"); dlcb = alpm_option_get_dlcb (); totaldlcb = alpm_option_get_totaldlcb (); /* set total size to minus the number of databases */ i = alpm_option_get_syncdbs (); totaldlcb (-alpm_list_count (i)); for (; i != NULL; i = i->next) { gint result; if (pk_backend_cancelled (self)) { /* pretend to be finished */ i = NULL; break; } result = alpm_db_update (force, i->data); if (result > 0) { /* fake the download when already up to date */ dlcb ("", 1, 1); } else if (result < 0) { g_set_error (error, ALPM_ERROR, pm_errno, "[%s]: %s", alpm_db_get_name (i->data), alpm_strerrorlast ()); break; } } totaldlcb (0); if (i == NULL) { return pk_backend_transaction_end (self, error); } else { pk_backend_transaction_end (self, NULL); return FALSE; } }
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); }
static int is_foreign(alpm_pkg_t *pkg) { const char *pkgname = alpm_pkg_get_name(pkg); alpm_list_t *j; alpm_list_t *sync_dbs = alpm_option_get_syncdbs(config->handle); int match = 0; for(j = sync_dbs; j; j = alpm_list_next(j)) { alpm_db_t *db = alpm_list_getdata(j); alpm_pkg_t *findpkg = alpm_db_get_pkg(db, pkgname); if(findpkg) { match = 1; break; } } if(match == 0) { return 1; } return 0; }
static void pk_backend_repo_disable_thread (PkBackendJob *job, GVariant *params, gpointer user_data) { const alpm_list_t *i; const gchar *repo; GError *error = NULL; repo = pk_backend_get_string (self, "repo_id"); for (i = alpm_option_get_syncdbs (); i != NULL; i = i->next) { pmdb_t *db = (pmdb_t *) i->data; const gchar *name = alpm_db_get_name (db); if (g_strcmp0 (repo, name) == 0) { if (alpm_db_unregister (db) < 0) { g_set_error (&error, ALPM_ERROR, pm_errno, "[%s]: %s", repo, alpm_strerrorlast ()); } else { g_hash_table_insert (disabled, g_strdup (repo), GINT_TO_POINTER (1)); } break; } } if (i == NULL) { int code = PM_ERR_DB_NULL; g_set_error (&error, ALPM_ERROR, code, "[%s]: %s", repo, alpm_strerror (code)); } if (error != NULL) { pk_backend_error (self, error); g_error_free (error); } pk_backend_job_finished (self); }
static void pk_backend_get_repo_list_thread (PkBackendJob *job, GVariant *params, gpointer user_data) { const alpm_list_t *i; GHashTableIter iter; gpointer key, value; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (disabled != NULL, FALSE); /* emit enabled repos */ for (i = alpm_option_get_syncdbs (); i != NULL; i = i->next) { pmdb_t *db = (pmdb_t *) i->data; const gchar *repo = alpm_db_get_name (db); if (pk_backend_cancelled (self)) { goto out; } else { pk_backend_repo_info (self, repo, TRUE); } } /* emit disabled repos */ g_hash_table_iter_init (&iter, disabled); while (g_hash_table_iter_next (&iter, &key, &value)) { const gchar *repo = (const gchar *) key; if (pk_backend_cancelled (self)) { goto out; } else { pk_backend_repo_info (self, repo, FALSE); } } out: pk_backend_finish (self, NULL); }
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; }
/* Lists detailed information about targets */ static int sync_info(CURL *curl, alpm_list_t *targets) { int found, ret, pkgcount; alpm_list_t *i, *j, *results; alpm_list_t *free_list = NULL; alpm_list_t *syncdbs = alpm_option_get_syncdbs(config->handle); alpm_pkg_t *spkg; char cwd[PATH_MAX]; char filename[PATH_MAX]; char url[PATH_MAX]; FILE *fp = NULL; int fd; struct aurpkg_t *pkg; if (!getcwd(cwd, PATH_MAX)) { return error(PW_ERR_GETCWD); } if (chdir(powaur_dir)) { return error(PW_ERR_CHDIR, powaur_dir); } found = ret = pkgcount = 0; for (i = targets; i; i = i->next, ++pkgcount) { /* Search sync dbs first */ spkg = search_syncdbs(syncdbs, i->data); if (spkg) { if (found++){ printf("\n"); } pacman_pkgdump(spkg, PKG_FROM_SYNC); spkg = NULL; continue; } results = query_aur(curl, i->data, AUR_QUERY_INFO); if (alpm_list_count(results) != 1) { if (pkgcount > 0) { printf("\n"); } pw_printf(PW_LOG_ERROR, "package %s not found\n", i->data); goto garbage_collect; } snprintf(filename, PATH_MAX, "%s.PKGBUILDXXXXXX", i->data); fd = mkstemp(filename); if (fd < 0) { error(PW_ERR_FOPEN, filename); goto garbage_collect; } fp = fdopen(fd, "w+"); if (!fp) { printf("NO\n"); error(PW_ERR_FOPEN, filename); goto garbage_collect; } snprintf(url, PATH_MAX, AUR_PKGBUILD_URL, i->data); /* Download the PKGBUILD and parse it */ ret = download_single_file(curl, url, fp); if (ret) { goto destroy_remnants; } /* Parse PKGBUILD and get detailed info */ fseek(fp, 0L, SEEK_SET); pkg = results->data; parse_pkgbuild(pkg, fp); if (found++) { printf("\n"); } printf("%s%s %saur%s\n", color.bold, REPO, color.bmag, color.nocolor); printf("%s%s %s%s\n", color.bold, NAME, pkg->name, color.nocolor); printf("%s%s %s%s%s\n", color.bold, VERSION, color.bgreen, pkg->version, color.nocolor); printf("%s%s %s%s%s\n", color.bold, URL, color.bcyan, pkg->url, color.nocolor); printf("%s%s%s ", color.bold, A_URL, color.bcyan); printf(AUR_PKG_URL, pkg->id); printf("%s\n", color.nocolor); printf("%s%s %s%s\n", color.bold, LICENSES, color.nocolor, pkg->license); printf("%s%s %s%d\n", color.bold, A_VOTES, color.nocolor, pkg->votes); printf("%s%s ", color.bold, A_OUTOFDATE); if (pkg->outofdate) { printf("%s%s", color.bred, "Yes"); } else { printf("%s%s", color.nocolor, "No"); } printf("%s\n", color.nocolor); print_list_prefix(pkg->provides, PROVIDES); print_list_prefix(pkg->depends, DEPS); print_list_prefix(pkg->optdepends, OPTDEPS); print_list_prefix(pkg->conflicts, CONFLICTS); print_list_prefix(pkg->replaces, REPLACES); print_list_prefix(pkg->arch, ARCH); printf("%s%s%s %s\n", color.bold, DESC, color.nocolor, pkg->desc); destroy_remnants: fclose(fp); fp = NULL; unlink(filename); garbage_collect: free_list = alpm_list_add(free_list, results); } cleanup: for (i = free_list; i; i = i->next) { alpm_list_free_inner(i->data, (alpm_list_fn_free) aurpkg_free); alpm_list_free(i->data); } alpm_list_free(free_list); if (chdir(cwd)) { return error(PW_ERR_RESTORECWD); } return found ? 0 : -1; }
/* 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_syncdbs(PyObject *self, PyObject *dummy) { alpm_handle_t *handle = ALPM_HANDLE(self); return alpmlist_to_pylist(alpm_option_get_syncdbs(handle), pyalpm_db_from_pmdb); }
/** * pacman_manager_get_sync_databases: * @manager: A #PacmanManager. * * Gets a list of registered sync databases. * * Returns: A list of #PacmanDatabase. Do not free. */ const PacmanList *pacman_manager_get_sync_databases (PacmanManager *manager) { g_return_val_if_fail (manager != NULL, NULL); return alpm_option_get_syncdbs (); }