From d7651598c859a1507fbf8816ba76568c41fc14c2 Mon Sep 17 00:00:00 2001 From: "Rafael G. Ruiz" Date: Sun, 10 Oct 2021 16:46:47 +0200 Subject: [PATCH] override replace: allow not freeze for --from option `override replace --experimental --from KIND=NAME` do not pin the overrided package allowing updates Signed-off-by: Rafael G. Ruiz --- rust/src/daemon.rs | 5 +++ rust/src/lib.rs | 1 + rust/src/origin.rs | 7 +++- rust/src/treefile.rs | 13 +++++++- src/app/rpmostree-builtin-status.cxx | 11 +++++++ src/libpriv/rpmostree-core.cxx | 1 + src/libpriv/rpmostree-origin.cxx | 48 ++++++++++++++++++++++++++-- src/libpriv/rpmostree-origin.h | 5 ++- 8 files changed, 85 insertions(+), 6 deletions(-) diff --git a/rust/src/daemon.rs b/rust/src/daemon.rs index 41deee01ee..7d87d467ce 100644 --- a/rust/src/daemon.rs +++ b/rust/src/daemon.rs @@ -108,6 +108,11 @@ fn deployment_populate_variant_origin( "requested-base-local-replacements", tf.derive.override_replace_local.as_ref(), ); + vdict_insert_optmap( + dict, + "requested-base-replacements", + tf.derive.override_replace.as_ref(), + ); // Initramfs data. if let Some(initramfs) = tf.derive.initramfs.as_ref() { diff --git a/rust/src/lib.rs b/rust/src/lib.rs index b0bc5ea2af..a0de9cd8c7 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -363,6 +363,7 @@ pub mod ffi { fn get_packages_local(&self) -> Vec; fn get_packages_local_fileoverride(&self) -> Vec; fn get_packages_override_replace_local(&self) -> Vec; + fn get_packages_override_replace(&self) -> Vec; fn get_packages_override_remove(&self) -> Vec; fn get_modules_enable(&self) -> Vec; fn get_modules_install(&self) -> Vec; diff --git a/rust/src/origin.rs b/rust/src/origin.rs index 91baa82c1f..5c3ca135fb 100644 --- a/rust/src/origin.rs +++ b/rust/src/origin.rs @@ -27,7 +27,8 @@ const OVERRIDES: &str = "overrides"; static UNORDERED_LIST_KEYS: phf::Set<&'static str> = phf::phf_set! { "packages/local", "packages/local-fileoverride", - "overrides/replace-local" + "overrides/replace-local", + "override/replace" }; #[context("Parsing origin")] @@ -60,6 +61,7 @@ pub(crate) fn origin_to_treefile_inner(kf: &KeyFile) -> Result> { } cfg.derive.override_remove = parse_stringlist(kf, OVERRIDES, "remove")?; cfg.derive.override_replace_local = parse_localpkglist(kf, OVERRIDES, "replace-local")?; + cfg.derive.override_replace = parse_localpkglist(kf, OVERRIDES, "replace")?; let regenerate_initramfs = kf .boolean(RPMOSTREE, "regenerate-initramfs") @@ -163,6 +165,9 @@ fn treefile_to_origin_inner(tf: &Treefile) -> Result { if let Some(pkgs) = tf.derive.override_replace_local.as_ref() { set_sha256_nevra_pkgs(&kf, OVERRIDES, "replace-local", pkgs) } + if let Some(pkgs) = tf.derive.override_replace.as_ref() { + set_sha256_nevra_pkgs(&kf, OVERRIDES, "replace", pkgs) + } if let Some(ref modcfg) = tf.modules { if let Some(modules) = modcfg.enable.as_deref() { let modules = modules.iter().map(|s| s.as_str()); diff --git a/rust/src/treefile.rs b/rust/src/treefile.rs index 5fe6ed4695..47228293a2 100644 --- a/rust/src/treefile.rs +++ b/rust/src/treefile.rs @@ -671,7 +671,15 @@ impl Treefile { .map(|(k, v)| format!("{}:{}", v, k)) .collect() } - + pub(crate) fn get_packages_override_replace(&self) -> Vec { + self.parsed + .derive + .override_replace + .iter() + .flatten() + .map(|(k, v)| format!("{}:{}", v, k)) + .collect() + } pub(crate) fn get_exclude_packages(&self) -> Vec { self.parsed.exclude_packages.clone().unwrap_or_default() } @@ -1364,6 +1372,8 @@ pub(crate) struct DeriveConfigFields { pub(crate) override_remove: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub(crate) override_replace_local: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub(crate) override_replace: Option>, // Initramfs #[serde(skip_serializing_if = "Option::is_none")] @@ -1394,6 +1404,7 @@ impl DeriveConfigFields { check!(packages_local_fileoverride); check!(override_remove); check!(override_replace_local); + check!(override_replace); check!(initramfs); check!(custom); Ok(()) diff --git a/src/app/rpmostree-builtin-status.cxx b/src/app/rpmostree-builtin-status.cxx index 58a73bd4c4..870d9b507d 100644 --- a/src/app/rpmostree-builtin-status.cxx +++ b/src/app/rpmostree-builtin-status.cxx @@ -590,6 +590,8 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy, g_autofree const gchar **origin_requested_base_removals = NULL; g_autoptr(GVariant) origin_base_local_replacements = NULL; g_autofree const gchar **origin_requested_base_local_replacements = NULL; + g_autoptr(GVariant) origin_base_replacements = NULL; + g_autofree const gchar **origin_requested_base_replacements = NULL; if (g_variant_dict_lookup (dict, "origin", "&s", &origin_refspec) || g_variant_dict_lookup (dict, "container-image-reference", "&s", &origin_refspec)) { @@ -616,6 +618,11 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy, G_VARIANT_TYPE ("a(vv)")); origin_requested_base_local_replacements = lookup_array_and_canonicalize (dict, "requested-base-local-replacements"); + origin_base_replacements = + g_variant_dict_lookup_value (dict, "base-replacements", + G_VARIANT_TYPE ("a(vv)")); + origin_requested_base_replacements = + lookup_array_and_canonicalize (dict, "requested-base-replacements"); } else origin_refspec = NULL; @@ -970,6 +977,10 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy, NULL, FALSE); } +// if (origin_requested_base_replacements) +// { +// +// } if (origin_requested_base_local_replacements && opt_verbose) print_packages ("InactiveBaseReplacements", max_key_len, diff --git a/src/libpriv/rpmostree-core.cxx b/src/libpriv/rpmostree-core.cxx index a57ba2d1f6..77c1383353 100644 --- a/src/libpriv/rpmostree-core.cxx +++ b/src/libpriv/rpmostree-core.cxx @@ -1718,6 +1718,7 @@ rpmostree_context_prepare (RpmOstreeContext *self, auto packages_local = self->treefile_rs->get_packages_local(); auto packages_local_fileoverride = self->treefile_rs->get_packages_local_fileoverride(); auto packages_override_replace_local = self->treefile_rs->get_packages_override_replace_local(); + auto packages_override_replace = self->treefile_rs->get_packages_override_replace(); auto packages_override_remove = self->treefile_rs->get_packages_override_remove(); auto exclude_packages = self->treefile_rs->get_exclude_packages (); auto modules_enable = self->treefile_rs->get_modules_enable(); diff --git a/src/libpriv/rpmostree-origin.cxx b/src/libpriv/rpmostree-origin.cxx index 9cefbad3c9..efd606ea90 100644 --- a/src/libpriv/rpmostree-origin.cxx +++ b/src/libpriv/rpmostree-origin.cxx @@ -53,7 +53,7 @@ struct RpmOstreeOrigin { GHashTable *cached_modules_install; /* set of module specs to install */ GHashTable *cached_local_packages; /* NEVRA --> header sha256 */ GHashTable *cached_local_fileoverride_packages; /* NEVRA --> header sha256 */ - /* GHashTable *cached_overrides_replace; XXX: NOT IMPLEMENTED YET */ + GHashTable *cached_overrides_replace; /* array of (sources, pkgnames[]) */ GHashTable *cached_overrides_local_replace; /* NEVRA --> header sha256 */ GHashTable *cached_overrides_remove; /* set of pkgnames (no EVRA) */ }; @@ -118,6 +118,8 @@ rpmostree_origin_parse_keyfile (GKeyFile *origin, g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); ret->cached_overrides_local_replace = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); + ret->cached_overrides_replace = + g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); ret->cached_overrides_remove = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); ret->cached_initramfs_etc_files = @@ -197,6 +199,10 @@ rpmostree_origin_parse_keyfile (GKeyFile *origin, ret->cached_overrides_local_replace, error)) return FALSE; + if (!parse_packages_strv (ret->kf, "overrides", "replace", TRUE, + ret->cached_overrides_replace, error)) + return FALSE; + g_auto(GStrv) initramfs_etc_files = g_key_file_get_string_list (ret->kf, "rpmostree", "initramfs-etc", NULL, NULL); for (char **f = initramfs_etc_files; f && *f; f++) @@ -303,6 +309,12 @@ rpmostree_origin_get_local_packages (RpmOstreeOrigin *origin) return origin->cached_local_packages; } +GHashTable * +rpmostree_origin_get_overrides_replace (RpmOstreeOrigin *origin) +{ + return origin->cached_overrides_replace; +} + GHashTable * rpmostree_origin_get_local_fileoverride_packages (RpmOstreeOrigin *origin) { @@ -381,6 +393,7 @@ rpmostree_origin_has_packages (RpmOstreeOrigin *origin) (g_hash_table_size (origin->cached_local_packages) > 0) || (g_hash_table_size (origin->cached_local_fileoverride_packages) > 0) || (g_hash_table_size (origin->cached_overrides_local_replace) > 0) || + (g_hash_table_size (origin->cached_overrides_replace) > 0) || (g_hash_table_size (origin->cached_overrides_remove) > 0) || (g_hash_table_size (origin->cached_modules_install) > 0); } @@ -425,6 +438,7 @@ rpmostree_origin_unref (RpmOstreeOrigin *origin) g_clear_pointer (&origin->cached_local_packages, g_hash_table_unref); g_clear_pointer (&origin->cached_local_fileoverride_packages, g_hash_table_unref); g_clear_pointer (&origin->cached_overrides_local_replace, g_hash_table_unref); + g_clear_pointer (&origin->cached_overrides_replace, g_hash_table_unref); g_clear_pointer (&origin->cached_overrides_remove, g_hash_table_unref); g_clear_pointer (&origin->cached_initramfs_etc_files, g_hash_table_unref); g_free (origin); @@ -1007,12 +1021,18 @@ rpmostree_origin_add_overrides (RpmOstreeOrigin *origin, if (!rpmostree_decompose_sha256_nevra (&pkg, &sha256, error)) return glnx_throw (error, "Invalid SHA-256 NEVRA string: %s", pkg); } + if (type == RPMOSTREE_ORIGIN_OVERRIDE_REPLACE) + { + if (!rpmostree_decompose_sha256_nevra (&pkg, &sha256, error)) + return glnx_throw (error, "Invalid SHA-256 NEVRA string: %s", pkg); + } /* Check that the same overrides don't already exist. Of course, in the local replace * case, this doesn't catch same pkg name but different EVRA; we'll just barf at that * later on in the core. This is just an early easy sanity check. */ if (g_hash_table_contains (origin->cached_overrides_remove, pkg) || - g_hash_table_contains (origin->cached_overrides_local_replace, pkg)) + g_hash_table_contains (origin->cached_overrides_local_replace, pkg) || + g_hash_table_contains (origin->cached_overrides_replace, pkg)) return glnx_throw (error, "Override already exists for package '%s'", pkg); if (type == RPMOSTREE_ORIGIN_OVERRIDE_REPLACE_LOCAL) @@ -1020,6 +1040,9 @@ rpmostree_origin_add_overrides (RpmOstreeOrigin *origin, util::move_nullify (sha256)); else if (type == RPMOSTREE_ORIGIN_OVERRIDE_REMOVE) g_hash_table_add (origin->cached_overrides_remove, g_strdup (pkg)); + else if (type == RPMOSTREE_ORIGIN_OVERRIDE_REPLACE) + g_hash_table_insert (origin->cached_overrides_replace, g_strdup (pkg), + util::move_nullify (sha256)); else g_assert_not_reached (); @@ -1031,6 +1054,9 @@ rpmostree_origin_add_overrides (RpmOstreeOrigin *origin, if (type == RPMOSTREE_ORIGIN_OVERRIDE_REPLACE_LOCAL) update_keyfile_pkgs_from_cache (origin, "overrides", "replace-local", origin->cached_overrides_local_replace, TRUE); + else if (type == RPMOSTREE_ORIGIN_OVERRIDE_REPLACE) + update_keyfile_pkgs_from_cache (origin, "overrides", "replace", + origin->cached_overrides_replace, TRUE); else if (type == RPMOSTREE_ORIGIN_OVERRIDE_REMOVE) update_keyfile_pkgs_from_cache (origin, "overrides", "remove", origin->cached_overrides_remove, FALSE); @@ -1054,6 +1080,15 @@ rpmostree_origin_remove_override (RpmOstreeOrigin *origin, update_keyfile_pkgs_from_cache (origin, "overrides", "replace-local", origin->cached_overrides_local_replace, TRUE); } + + if (type == RPMOSTREE_ORIGIN_OVERRIDE_REPLACE) + { + if (!g_hash_table_remove (origin->cached_overrides_replace, package)) + return FALSE; + update_keyfile_pkgs_from_cache (origin, "overrides", "replace", + origin->cached_overrides_replace, TRUE); + } + else if (type == RPMOSTREE_ORIGIN_OVERRIDE_REMOVE) { if (!g_hash_table_remove (origin->cached_overrides_remove, package)) @@ -1075,6 +1110,10 @@ rpmostree_origin_remove_all_overrides (RpmOstreeOrigin *origin, gboolean remove_changed = (g_hash_table_size (origin->cached_overrides_remove) > 0); g_hash_table_remove_all (origin->cached_overrides_remove); + gboolean replace_changed = + (g_hash_table_size (origin->cached_overrides_replace) > 0); + g_hash_table_remove_all (origin->cached_overrides_replace); + gboolean local_replace_changed = (g_hash_table_size (origin->cached_overrides_local_replace) > 0); g_hash_table_remove_all (origin->cached_overrides_local_replace); @@ -1085,7 +1124,10 @@ rpmostree_origin_remove_all_overrides (RpmOstreeOrigin *origin, if (local_replace_changed) update_keyfile_pkgs_from_cache (origin, "overrides", "replace-local", origin->cached_overrides_local_replace, TRUE); + if (replace_changed) + update_keyfile_pkgs_from_cache (origin, "overrides", "replace", + origin->cached_overrides_replace, TRUE); - set_changed (out_changed, remove_changed || local_replace_changed); + set_changed (out_changed, remove_changed || local_replace_changed || replace_changed); return TRUE; } diff --git a/src/libpriv/rpmostree-origin.h b/src/libpriv/rpmostree-origin.h index e7d0a7bf5b..e9841a7c5a 100644 --- a/src/libpriv/rpmostree-origin.h +++ b/src/libpriv/rpmostree-origin.h @@ -92,6 +92,9 @@ rpmostree_origin_get_local_fileoverride_packages (RpmOstreeOrigin *origin); GHashTable * rpmostree_origin_get_overrides_remove (RpmOstreeOrigin *origin); +GHashTable * +rpmostree_origin_get_overrides_replace (RpmOstreeOrigin *origin); + GHashTable * rpmostree_origin_get_overrides_local_replace (RpmOstreeOrigin *origin); @@ -199,7 +202,7 @@ rpmostree_origin_remove_modules (RpmOstreeOrigin *origin, GError **error); typedef enum { - /* RPMOSTREE_ORIGIN_OVERRIDE_REPLACE, */ + RPMOSTREE_ORIGIN_OVERRIDE_REPLACE, RPMOSTREE_ORIGIN_OVERRIDE_REPLACE_LOCAL, RPMOSTREE_ORIGIN_OVERRIDE_REMOVE } RpmOstreeOriginOverrideType;