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; }
static gchar * alpm_pkg_build_replaces (pmpkg_t *pkg) { const alpm_list_t *i; GString *string = NULL; g_return_val_if_fail (pkg != NULL, NULL); g_return_val_if_fail (localdb != NULL, NULL); /* make a list of the packages that package replaces */ for (i = alpm_pkg_get_replaces (pkg); i != NULL; i = i->next) { pmpkg_t *replaces = alpm_db_get_pkg (localdb, i->data); if (replaces != NULL) { gchar *package = alpm_pkg_build_id (replaces); if (string == NULL) { string = g_string_new (package); } else { g_string_append_printf (string, "&%s", package); } g_free (package); } } if (string != NULL) { return g_string_free (string, FALSE); } else { return NULL; } }
static int remove_target(const char *target) { alpm_pkg_t *pkg; alpm_db_t *db_local = alpm_get_localdb(config->handle); alpm_list_t *p; if((pkg = alpm_db_get_pkg(db_local, target)) != NULL) { if(alpm_remove_pkg(config->handle, pkg) == -1) { pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", target, alpm_strerror(alpm_errno(config->handle))); return -1; } config->explicit_removes = alpm_list_add(config->explicit_removes, pkg); return 0; } /* fallback to group */ alpm_group_t *grp = alpm_db_get_group(db_local, target); if(grp == NULL) { pm_printf(ALPM_LOG_ERROR, _("target not found: %s\n"), target); return -1; } for(p = grp->packages; p; p = alpm_list_next(p)) { pkg = p->data; if(alpm_remove_pkg(config->handle, pkg) == -1) { pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", target, alpm_strerror(alpm_errno(config->handle))); return -1; } config->explicit_removes = alpm_list_add(config->explicit_removes, pkg); } return 0; }
static alpm_list_t * pk_backend_find_requirer (PkBackend *self, alpm_list_t *pkgs, const gchar *name, GError **error) { alpm_pkg_t *requirer; g_return_val_if_fail (self != NULL, pkgs); g_return_val_if_fail (name != NULL, pkgs); g_return_val_if_fail (localdb != NULL, pkgs); if (alpm_list_find_pkg (pkgs, name) != NULL) { return pkgs; } /* look for local requirers */ requirer = alpm_db_get_pkg (localdb, name); if (requirer != NULL) { pk_backend_pkg (self, requirer, PK_INFO_ENUM_INSTALLED); if (pk_backend_get_bool (self, "recursive")) { pkgs = alpm_list_add (pkgs, requirer); } } else { int code = ALPM_ERR_PKG_NOT_FOUND; g_set_error (error, ALPM_ERROR, code, "%s: %s", name, alpm_strerror (code)); } return pkgs; }
static gboolean pk_alpm_pkg_is_local (PkBackendJob *job, alpm_pkg_t *pkg) { PkBackend *backend = pk_backend_job_get_backend (job); PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend); alpm_pkg_t *local; g_return_val_if_fail (pkg != NULL, FALSE); /* find an installed package with the same name */ local = alpm_db_get_pkg (priv->localdb, alpm_pkg_get_name (pkg)); if (local == NULL) return FALSE; /* make sure the installed version is the same */ if (alpm_pkg_vercmp (alpm_pkg_get_version (local), alpm_pkg_get_version (pkg)) != 0) { return FALSE; } /* make sure the installed arch is the same */ if (g_strcmp0 (alpm_pkg_get_arch (local), alpm_pkg_get_arch (pkg)) != 0) { return FALSE; } return TRUE; }
static gchar * pk_alpm_pkg_build_replaces (PkBackendJob *job, alpm_pkg_t *pkg) { PkBackend *backend = pk_backend_job_get_backend (job); PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend); const alpm_list_t *i; GString *string = NULL; g_return_val_if_fail (pkg != NULL, NULL); /* make a list of the packages that package replaces */ for (i = alpm_pkg_get_replaces (pkg); i != NULL; i = i->next) { alpm_pkg_t *replaces = alpm_db_get_pkg (priv->localdb, i->data); if (replaces != NULL) { _cleanup_free_ gchar *package = pk_alpm_pkg_build_id (replaces); if (string == NULL) { string = g_string_new (package); } else { g_string_append_printf (string, "&%s", package); } } } if (string == NULL) return NULL; return g_string_free (string, FALSE); }
void display_targets(void) { alpm_list_t *i, *targets = NULL; alpm_db_t *db_local = alpm_get_localdb(config->handle); for(i = alpm_trans_get_add(config->handle); i; i = alpm_list_next(i)) { alpm_pkg_t *pkg = i->data; pm_target_t *targ = calloc(1, sizeof(pm_target_t)); if(!targ) return; targ->install = pkg; targ->remove = alpm_db_get_pkg(db_local, alpm_pkg_get_name(pkg)); if(alpm_list_find(config->explicit_adds, pkg, pkg_cmp)) { targ->is_explicit = 1; } targets = alpm_list_add(targets, targ); } for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) { alpm_pkg_t *pkg = i->data; pm_target_t *targ = calloc(1, sizeof(pm_target_t)); if(!targ) return; targ->remove = pkg; if(alpm_list_find(config->explicit_removes, pkg, pkg_cmp)) { targ->is_explicit = 1; } targets = alpm_list_add(targets, targ); } targets = alpm_list_msort(targets, alpm_list_count(targets), target_cmp); _display_targets(targets, config->verbosepkglists); FREELIST(targets); }
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; }
VALUE db_find ( VALUE self, VALUE pkgname ) { pmpkg_t * pkg; INITDBPTR; pkg = alpm_db_get_pkg( db, StringValueCStr( pkgname )); return ( pkg == NULL ? Qnil : PKG2OBJ( pkg )); }
static gboolean pk_backend_resolve_name (PkBackend *self, const gchar *name, GError **error) { alpm_pkg_t *pkg; int code; PkBitfield filters; gboolean skip_local, skip_remote; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (name != NULL, FALSE); g_return_val_if_fail (alpm != NULL, FALSE); g_return_val_if_fail (localdb != NULL, FALSE); 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); pkg = alpm_db_get_pkg (localdb, name); if (pkg != NULL) { if (!skip_local) { pk_backend_pkg (self, pkg, PK_INFO_ENUM_INSTALLED); return TRUE; } } else if (!skip_remote) { const alpm_list_t *i = alpm_get_syncdbs (alpm); for (; i != NULL; i = i->next) { pkg = alpm_db_get_pkg (i->data, name); if (pkg != NULL) { pk_backend_pkg (self, pkg, PK_INFO_ENUM_AVAILABLE); return TRUE; } } } code = ALPM_ERR_PKG_NOT_FOUND; g_set_error (error, ALPM_ERROR, code, "%s: %s", name, alpm_strerror (code)); return FALSE; }
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; }
alpm_pkg_t * pk_backend_find_pkg (PkBackend *self, const gchar *package_id, GError **error) { gchar **package; const gchar *repo_id; alpm_db_t *db = NULL; alpm_pkg_t *pkg; g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (package_id != NULL, NULL); g_return_val_if_fail (alpm != NULL, NULL); g_return_val_if_fail (localdb != NULL, NULL); package = pk_package_id_split (package_id); repo_id = package[PK_PACKAGE_ID_DATA]; /* find the database to search in */ if (g_strcmp0 (repo_id, "installed") == 0) { db = localdb; } else { const alpm_list_t *i = alpm_get_syncdbs (alpm); for (; i != NULL; i = i->next) { const gchar *repo = alpm_db_get_name (i->data); if (g_strcmp0 (repo, repo_id) == 0) { db = i->data; break; } } } if (db != NULL) { pkg = alpm_db_get_pkg (db, package[PK_PACKAGE_ID_NAME]); } else { pkg = NULL; } if (pkg != NULL) { const gchar *version = alpm_pkg_get_version (pkg); if (g_strcmp0 (version, package[PK_PACKAGE_ID_VERSION]) != 0) { pkg = NULL; } } if (pkg == NULL) { int code = ALPM_ERR_PKG_NOT_FOUND; g_set_error (error, ALPM_ERROR, code, "%s: %s", package_id, alpm_strerror (code)); } g_strfreev (package); return pkg; }
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; }
/** * call-seq: * get( name ) → a_package * * Find a Package by name in the database. * * === Parameters * [name] * The name of the package. Must match exactly. * * === Return value * A Package instance representing the package. */ static VALUE get(VALUE self, VALUE name) { alpm_db_t* p_db = NULL; alpm_pkg_t* p_pkg = NULL; Data_Get_Struct(self, alpm_db_t, p_db); p_pkg = alpm_db_get_pkg(p_db, StringValuePtr(name)); if (p_pkg) return Data_Wrap_Struct(rb_cAlpm_Package, NULL, NULL, p_pkg); else return Qnil; }
alpm_pkg_t *load_pkg(const char *pkgname) { /* TODO pkgspec handling */ if(strncmp(pkgname, "local/", 6) == 0) { pkgname += 6; } alpm_pkg_t *p = alpm_db_get_pkg(localdb, pkgname); if(p == NULL) { fprintf(stderr, "error: could not find package '%s'\n", pkgname); } else { packages = list_add_unique(packages, p); } return p; }
static alpm_list_t *resolve_pkg(alpm_list_t *targets) { char *pkgname, *reponame; alpm_list_t *t, *r, *ret = NULL; if (targets == NULL) { return all_packages(dblist); } else if (opt_search) { return search_packages(dblist, targets); } else if (opt_groups) { return search_groups(dblist, targets); } /* resolve each target individually from the repo pool */ for (t = targets; t; t = alpm_list_next(t)) { alpm_pkg_t *pkg = NULL; int found = 0; pkgname = reponame = t->data; if (strchr(pkgname, '/')) { strsep(&pkgname, "/"); } else { reponame = NULL; } for (r = dblist; r; r = alpm_list_next(r)) { alpm_db_t *repo = r->data; if (reponame && strcmp(reponame, alpm_db_get_name(repo)) != 0) { continue; } pkg = alpm_db_get_pkg(repo, pkgname); if (pkg == NULL) { continue; } found = 1; ret = alpm_list_add(ret, pkg); if (opt_readone) { break; } } if (!found && opt_verbose) { fprintf(stderr, "error: package `%s' not found\n", pkgname); } } return ret; }
/** * @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; }
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; }
void print_installed(alpm_db_t *db_local, alpm_pkg_t *pkg) { const char *pkgname = alpm_pkg_get_name(pkg); const char *pkgver = alpm_pkg_get_version(pkg); alpm_pkg_t *lpkg = alpm_db_get_pkg(db_local, pkgname); if(lpkg) { const char *lpkgver = alpm_pkg_get_version(lpkg); const colstr_t *colstr = &config->colstr; if(strcmp(lpkgver, pkgver) == 0) { printf(" %s[%s]%s", colstr->meta, _("installed"), colstr->nocolor); } else { printf(" %s[%s: %s]%s", colstr->meta, _("installed"), lpkgver, colstr->nocolor); } } }
void pk_backend_transaction_packages (PkBackend *self) { const alpm_list_t *i; PkInfoEnum info; g_return_if_fail (self != NULL); g_return_if_fail (alpm != NULL); g_return_if_fail (localdb != NULL); /* emit packages that would have been installed */ for (i = alpm_trans_get_add (alpm); i != NULL; i = i->next) { if (pk_backend_cancelled (self)) { break; } else { const gchar *name = alpm_pkg_get_name (i->data); if (alpm_db_get_pkg (localdb, name) != NULL) { info = PK_INFO_ENUM_UPDATING; } else { info = PK_INFO_ENUM_INSTALLING; } pk_backend_pkg (self, i->data, info); } } switch (pk_backend_job_get_role (self)) { case PK_ROLE_ENUM_SIMULATE_UPDATE_PACKAGES: info = PK_INFO_ENUM_OBSOLETING; break; default: info = PK_INFO_ENUM_REMOVING; break; } /* emit packages that would have been removed */ for (i = alpm_trans_get_remove (alpm); i != NULL; i = i->next) { if (pk_backend_cancelled (self)) { break; } else { pk_backend_pkg (self, i->data, info); } } }
/** 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); }
static alpm_list_t *search_exact(alpm_list_t *dblist, alpm_list_t *targets) { char *pkgname, *reponame; alpm_list_t *results = NULL; /* resolve each target individually from the repo pool */ for(alpm_list_t *t = targets; t; t = t->next) { alpm_pkg_t *pkg = NULL; alpm_list_t *r; int found = 0; pkgname = reponame = t->data; if(strchr(pkgname, '/')) { strsep(&pkgname, "/"); } else { reponame = NULL; } for(r = dblist; r; r = r->next) { alpm_db_t *repo = r->data; if(reponame && strcmp(reponame, alpm_db_get_name(repo)) != 0) { continue; } pkg = alpm_db_get_pkg(repo, pkgname); if(pkg == NULL) { continue; } found = 1; results = alpm_list_add(results, pkg); if(opt_readone) { break; } } if(!found && opt_verbose) { fprintf(stderr, "error: package `%s' not found\n", pkgname); } } return results; }
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 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 gboolean pk_alpm_transaction_remove_targets (PkBackendJob *job, gchar** packages, GError **error) { PkBackend *backend = pk_backend_job_get_backend (job); PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend); g_return_val_if_fail (packages != NULL, FALSE); for (; *packages != NULL; ++packages) { g_auto(GStrv) package = pk_package_id_split (*packages); gchar *name = package[PK_PACKAGE_ID_NAME]; alpm_pkg_t *pkg = alpm_db_get_pkg (priv->localdb, name); if (pkg == NULL || alpm_remove_pkg (priv->alpm, pkg) < 0) { alpm_errno_t errno = alpm_errno (priv->alpm); g_set_error (error, PK_ALPM_ERROR, errno, "%s: %s", name, alpm_strerror (errno)); return FALSE; } } return TRUE; }
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; }
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 gboolean pk_backend_get_update_detail_thread (PkBackend *self) { gchar **packages; GError *error = NULL; g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (localdb != NULL, FALSE); packages = pk_backend_get_strv (self, "package_ids"); g_return_val_if_fail (packages != NULL, FALSE); /* collect details about updates */ for (; *packages != NULL; ++packages) { pmpkg_t *pkg, *old; pmdb_t *db; gchar *upgrades, *replaces, *urls; const gchar *reason; PkRestartEnum restart; PkUpdateStateEnum state; GTimeVal built = { 0 }, installed = { 0 }; gchar *issued, *updated; if (pk_backend_cancelled (self)) { break; } pkg = pk_backend_find_pkg (self, *packages, &error); if (pkg == NULL) { break; } old = alpm_db_get_pkg (localdb, alpm_pkg_get_name (pkg)); if (old != NULL) { upgrades = alpm_pkg_build_id (old); if (alpm_pkg_same_pkgver (pkg, old)) { reason = "Update to a newer release"; } else { reason = "Update to a new upstream version"; } } else { upgrades = NULL; reason = "Install to replace an older package"; } db = alpm_pkg_get_db (pkg); replaces = alpm_pkg_build_replaces (pkg); urls = alpm_pkg_build_urls (pkg); if (g_str_has_prefix (alpm_pkg_get_name (pkg), "kernel")) { restart = PK_RESTART_ENUM_SYSTEM; } else { restart = PK_RESTART_ENUM_NONE; } if (g_str_has_suffix (alpm_db_get_name (db), "testing")) { state = PK_UPDATE_STATE_ENUM_TESTING; } else { state = PK_UPDATE_STATE_ENUM_STABLE; } built.tv_sec = alpm_pkg_get_builddate (pkg); if (built.tv_sec > 0) { issued = g_time_val_to_iso8601 (&built); } else { issued = NULL; } if (upgrades != NULL) { installed.tv_sec = alpm_pkg_get_installdate (old); if (installed.tv_sec > 0) { updated = g_time_val_to_iso8601 (&installed); } else { updated = NULL; } } else { updated = NULL; } pk_backend_update_detail (self, *packages, upgrades, replaces, urls, NULL, NULL, restart, reason, NULL, state, issued, updated); g_free (issued); g_free (updated); g_free (urls); g_free (replaces); g_free (upgrades); } return pk_backend_finish (self, error); }