/** * dnf_db_get_dir_for_package: **/ static gchar * dnf_db_get_dir_for_package(DnfDb *db, DnfPackage *package) { const gchar *pkgid; DnfDbPrivate *priv = GET_PRIVATE(db); const gchar *instroot; #ifdef BUILDOPT_USE_DNF_YUMDB static const gchar *yumdb_dir = "/var/lib/dnf/yumdb"; #else static const gchar *yumdb_dir = "/var/lib/yum/yumdb"; #endif pkgid = dnf_package_get_pkgid(package); if (pkgid == NULL) return NULL; instroot = dnf_context_get_install_root(priv->context); if (g_strcmp0(instroot, "/") == 0) instroot = ""; return g_strdup_printf("%s%s/%c/%s-%s-%s-%s-%s", instroot, yumdb_dir, dnf_package_get_name(package)[0], pkgid, dnf_package_get_name(package), dnf_package_get_version(package), dnf_package_get_release(package), dnf_package_get_arch(package)); }
END_TEST START_TEST(test_goal_get_reason) { DnfPackage *pkg = get_latest_pkg(test_globals.sack, "walrus"); HyGoal goal = hy_goal_create(test_globals.sack); hy_goal_install(goal, pkg); g_object_unref(pkg); hy_goal_run(goal); GPtrArray *plist = hy_goal_list_installs(goal, NULL); guint i; int set = 0; for(i = 0; i < plist->len; i++) { pkg = g_ptr_array_index (plist, i); if (!strcmp(dnf_package_get_name(pkg), "walrus")) { set |= 1 << 0; fail_unless(hy_goal_get_reason(goal, pkg) == HY_REASON_USER); } if (!strcmp(dnf_package_get_name(pkg), "semolina")) { set |= 1 << 1; fail_unless(hy_goal_get_reason(goal, pkg) == HY_REASON_DEP); } } fail_unless(set == 3); g_ptr_array_unref(plist); hy_goal_free(goal); }
gboolean rpmostree_posttrans_run_sync (DnfPackage *pkg, Header hdr, GHashTable *ignore_scripts, int rootfs_fd, GCancellable *cancellable, GError **error) { for (guint i = 0; i < G_N_ELEMENTS (posttrans_scripts); i++) { const char *desc = posttrans_scripts[i].desc; rpmTagVal tagval = posttrans_scripts[i].tag; rpmTagVal progtagval = posttrans_scripts[i].progtag; const char *script; g_autofree char **args = NULL; RpmOstreeScriptAction action; struct rpmtd_s td; if (!(headerIsEntry (hdr, tagval) || headerIsEntry (hdr, progtagval))) continue; script = headerGetString (hdr, tagval); if (!script) continue; if (headerGet (hdr, progtagval, &td, (HEADERGET_ALLOC|HEADERGET_ARGV))) args = td.data; action = lookup_script_action (pkg, ignore_scripts, desc); switch (action) { case RPMOSTREE_SCRIPT_ACTION_DEFAULT: { static const char lua[] = "<lua>"; if (args && args[0] && strcmp (args[0], lua) == 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Package '%s' has (currently) unsupported %s script in '%s'", dnf_package_get_name (pkg), lua, desc); return FALSE; } rpmostree_output_task_begin ("Running %s for %s...", desc, dnf_package_get_name (pkg)); if (!run_script_in_bwrap_container (rootfs_fd, dnf_package_get_name (pkg), desc, script, cancellable, error)) { g_prefix_error (error, "Running %s for %s: ", desc, dnf_package_get_name (pkg)); return FALSE; } rpmostree_output_task_end ("done"); } case RPMOSTREE_SCRIPT_ACTION_IGNORE: continue; } } return TRUE; }
/** * dnf_package_get_delta_from_evr: * @pkg: a #DnfPackage instance. * @from_evr: the EVR string of what's installed * * Gets the package delta for the package given an existing EVR. * * Returns: a #DnfPackageDelta, or %NULL * * Since: 0.7.0 */ DnfPackageDelta * dnf_package_get_delta_from_evr(DnfPackage *pkg, const char *from_evr) { Pool *pool = dnf_package_get_pool(pkg); Solvable *s = get_solvable(pkg); DnfPackageDelta *delta = NULL; Dataiterator di; const char *name = dnf_package_get_name(pkg); dataiterator_init(&di, pool, s->repo, SOLVID_META, DELTA_PACKAGE_NAME, name, SEARCH_STRING); dataiterator_prepend_keyname(&di, REPOSITORY_DELTAINFO); while (dataiterator_step(&di)) { dataiterator_setpos_parent(&di); if (pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_EVR) != s->evr || pool_lookup_id(pool, SOLVID_POS, DELTA_PACKAGE_ARCH) != s->arch) continue; const char * base_evr = pool_id2str(pool, pool_lookup_id(pool, SOLVID_POS, DELTA_BASE_EVR)); if (strcmp(base_evr, from_evr)) continue; // we have the right delta info, set up DnfPackageDelta *and break out: delta = dnf_packagedelta_new(pool); break; } dataiterator_free(&di); return delta; }
/** * dnf_package_get_package_id: * @pkg: a #DnfPackage *instance. * * Gets the package-id as used by PackageKit. * * Returns: the package_id string, or %NULL, e.g. "hal;2:0.3.4;i386;installed:fedora" * * Since: 0.1.0 **/ const gchar * dnf_package_get_package_id(DnfPackage *pkg) { DnfPackagePrivate *priv; const gchar *reponame; g_autofree gchar *reponame_tmp = NULL; priv = dnf_package_get_priv(pkg); if (priv == NULL) return NULL; if (priv->package_id != NULL) goto out; /* calculate and cache */ reponame = dnf_package_get_reponame(pkg); if (g_strcmp0(reponame, HY_SYSTEM_REPO_NAME) == 0) { /* origin data to munge into the package_id data field */ if (priv->origin != NULL) { reponame_tmp = g_strdup_printf("installed:%s", priv->origin); reponame = reponame_tmp; } else { reponame = "installed"; } } else if (g_strcmp0(reponame, HY_CMDLINE_REPO_NAME) == 0) { reponame = "local"; } priv->package_id = dnf_package_id_build(dnf_package_get_name(pkg), dnf_package_get_evr(pkg), dnf_package_get_arch(pkg), reponame); out: return priv->package_id; }
static RpmOstreeScriptAction lookup_script_action (DnfPackage *package, GHashTable *ignored_scripts, const char *scriptdesc) { const char *pkg_script = glnx_strjoina (dnf_package_get_name (package), ".", scriptdesc+1); const struct RpmOstreePackageScriptHandler *handler = rpmostree_script_gperf_lookup (pkg_script, strlen (pkg_script)); if (ignored_scripts && g_hash_table_contains (ignored_scripts, pkg_script)) return RPMOSTREE_SCRIPT_ACTION_IGNORE; if (!handler) return RPMOSTREE_SCRIPT_ACTION_DEFAULT; return handler->action; }
/** * dnf_package_is_installonly: * @pkg: a #DnfPackage *instance. * * Returns: %TRUE if the package can be installed more than once * * Since: 0.1.0 */ gboolean dnf_package_is_installonly(DnfPackage *pkg) { const gchar **installonly_pkgs; const gchar *pkg_name; guint i; installonly_pkgs = dnf_context_get_installonly_pkgs(NULL); pkg_name = dnf_package_get_name(pkg); for (i = 0; installonly_pkgs[i] != NULL; i++) { if (g_strcmp0(pkg_name, installonly_pkgs[i]) == 0) return TRUE; } return FALSE; }
/** * dnf_package_is_downloaded: * @pkg: a #DnfPackage *instance. * * Returns: %TRUE if the package is already downloaded * * Since: 0.1.0 **/ gboolean dnf_package_is_downloaded(DnfPackage *pkg) { const gchar *filename; if (dnf_package_installed(pkg)) return FALSE; filename = dnf_package_get_filename(pkg); if (filename == NULL) { g_warning("Failed to get cache filename for %s", dnf_package_get_name(pkg)); return FALSE; } return g_file_test(filename, G_FILE_TEST_EXISTS); }
/** * dnf_package_is_devel: * @pkg: a #DnfPackage *instance. * * Returns: %TRUE if the package is a development package * * Since: 0.1.0 **/ gboolean dnf_package_is_devel(DnfPackage *pkg) { const gchar *name; name = dnf_package_get_name(pkg); if (g_str_has_suffix(name, "-debuginfo")) return TRUE; if (g_str_has_suffix(name, "-devel")) return TRUE; if (g_str_has_suffix(name, "-static")) return TRUE; if (g_str_has_suffix(name, "-libs")) return TRUE; return FALSE; }
END_TEST START_TEST(test_goal_install_selector_file) { DnfSack *sack = test_globals.sack; HySelector sltr = hy_selector_create(sack); HyGoal goal = hy_goal_create(sack); fail_if(hy_selector_set(sltr, HY_PKG_FILE, HY_EQ|HY_GLOB, "/*/answers")); fail_if(hy_goal_erase_selector(goal, sltr)); fail_if(hy_goal_run(goal)); assert_iueo(goal, 0, 0, 1, 0); GPtrArray *plist = hy_goal_list_erasures(goal, NULL); DnfPackage *pkg = g_ptr_array_index(plist, 0); ck_assert_str_eq("fool", dnf_package_get_name(pkg)); hy_selector_free(sltr); g_ptr_array_unref(plist); hy_goal_free(goal); }
END_TEST static void assert_list_names(GPtrArray *plist, ...) { va_list names; char *name; int count = plist->len, i = 0; va_start(names, plist); while ((name = va_arg(names, char *)) != NULL) { if (i >= count) fail("assert_list_names(): list too short"); DnfPackage *pkg = g_ptr_array_index(plist, i++); ck_assert_str_eq(dnf_package_get_name(pkg), name); } fail_unless(i == count, "assert_list_names(): too many items in the list"); va_end(names); }
gboolean rpmostree_script_txn_validate (DnfPackage *package, Header hdr, GHashTable *override_ignored_scripts, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; guint i; for (i = 0; i < G_N_ELEMENTS (unsupported_scripts); i++) { const char *desc = unsupported_scripts[i].desc; rpmTagVal tagval = unsupported_scripts[i].tag; rpmTagVal progtagval = unsupported_scripts[i].progtag; RpmOstreeScriptAction action; if (!(headerIsEntry (hdr, tagval) || headerIsEntry (hdr, progtagval))) continue; action = lookup_script_action (package, override_ignored_scripts, desc); switch (action) { case RPMOSTREE_SCRIPT_ACTION_DEFAULT: { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Package '%s' has (currently) unsupported script of type '%s'", dnf_package_get_name (package), desc); goto out; } case RPMOSTREE_SCRIPT_ACTION_IGNORE: continue; } } ret = TRUE; out: return ret; }
/** * rpm_ostree_db_diff: * @repo: An OSTree repository * @orig_ref: Original ref (branch or commit) * @new_ref: New ref (branch or commit) * @out_removed: (out) (transfer container) (element-type RpmOstreePackage): Return location for removed packages * @out_added: (out) (transfer container) (element-type RpmOstreePackage): Return location for added packages * @out_modified_old: (out) (transfer container) (element-type RpmOstreePackage): Return location for modified old packages * @out_modified_new: (out) (transfer container) (element-type RpmOstreePackage): Return location for modified new packages * * Compute the RPM package delta between two commits. Currently you * must use %NULL for the @query parameter; in a future version this * function may allow looking at a subset of the packages. * * The @out_modified_old and @out_modified_new arrays will always be * the same length, and indicies will refer to the same base package * name. It is possible in RPM databases to have multiple packages * installed with the same name; in this case, the behavior will * depend on whether the package set is transitioning from 1 -> N or N * -> 1. In the former case, an arbitrary single instance of one of * the new packages will be in @out_modified_new. If the latter, then * multiple entries with the same name will be returned in * the array @out_modified_old, with each having a reference to the * single corresponding new package. */ gboolean rpm_ostree_db_diff (OstreeRepo *repo, const char *orig_ref, const char *new_ref, GPtrArray **out_removed, GPtrArray **out_added, GPtrArray **out_modified_old, GPtrArray **out_modified_new, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; g_autoptr(RpmOstreeRefSack) orig_sack = NULL; g_autoptr(RpmOstreeRefSack) new_sack = NULL; g_autoptr(GPtrArray) orig_pkglist = NULL; g_autoptr(GPtrArray) new_pkglist = NULL; g_autoptr(GPtrArray) ret_removed = g_ptr_array_new_with_free_func (g_object_unref); g_autoptr(GPtrArray) ret_added = g_ptr_array_new_with_free_func (g_object_unref); g_autoptr(GPtrArray) ret_modified_old = g_ptr_array_new_with_free_func (g_object_unref); g_autoptr(GPtrArray) ret_modified_new = g_ptr_array_new_with_free_func (g_object_unref); guint i; g_return_val_if_fail (out_removed != NULL && out_added != NULL && out_modified_old != NULL && out_modified_new != NULL, FALSE); orig_sack = rpmostree_get_refsack_for_commit (repo, orig_ref, cancellable, error); if (!orig_sack) goto out; { HyQuery query = hy_query_create (orig_sack->sack); hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); orig_pkglist = hy_query_run (query); hy_query_free (query); } new_sack = rpmostree_get_refsack_for_commit (repo, new_ref, cancellable, error); if (!new_sack) goto out; { HyQuery query = hy_query_create (new_sack->sack); hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); new_pkglist = hy_query_run (query); hy_query_free (query); } for (i = 0; i < new_pkglist->len; i++) { DnfPackage *pkg = new_pkglist->pdata[i]; HyQuery query = NULL; g_autoptr(GPtrArray) pkglist = NULL; guint count; DnfPackage *oldpkg; query = hy_query_create (orig_sack->sack); hy_query_filter (query, HY_PKG_NAME, HY_EQ, dnf_package_get_name (pkg)); hy_query_filter (query, HY_PKG_EVR, HY_NEQ, dnf_package_get_evr (pkg)); hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); pkglist = hy_query_run (query); count = pkglist->len; if (count > 0) { /* See comment above about transitions from N -> 1 */ oldpkg = pkglist->pdata[0]; g_ptr_array_add (ret_modified_old, _rpm_ostree_package_new (orig_sack, oldpkg)); g_ptr_array_add (ret_modified_new, _rpm_ostree_package_new (new_sack, pkg)); } } for (i = 0; i < orig_pkglist->len; i++) { DnfPackage *pkg = orig_pkglist->pdata[i]; HyQuery query = NULL; g_autoptr(GPtrArray) pkglist = NULL; query = hy_query_create (new_sack->sack); hy_query_filter (query, HY_PKG_NAME, HY_EQ, dnf_package_get_name (pkg)); hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); pkglist = hy_query_run (query); if (pkglist->len == 0) g_ptr_array_add (ret_removed, _rpm_ostree_package_new (orig_sack, pkg)); hy_query_free (query); } for (i = 0; i < new_pkglist->len; i++) { DnfPackage *pkg = new_pkglist->pdata[i]; HyQuery query = NULL; g_autoptr(GPtrArray) pkglist = NULL; query = hy_query_create (orig_sack->sack); hy_query_filter (query, HY_PKG_NAME, HY_EQ, dnf_package_get_name (pkg)); hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME); pkglist = hy_query_run (query); if (pkglist->len == 0) g_ptr_array_add (ret_added, _rpm_ostree_package_new (new_sack, pkg)); hy_query_free (query); } ret = TRUE; *out_removed = g_steal_pointer (&ret_removed); *out_added = g_steal_pointer (&ret_added); *out_modified_old = g_steal_pointer (&ret_modified_old); *out_modified_new = g_steal_pointer (&ret_modified_new); out: return ret; }