Skip to content

Commit

Permalink
override replace: allow not freeze for --from option
Browse files Browse the repository at this point in the history
`override replace --experimental --from KIND=NAME` do not pin the
overrided package allowing updates

Signed-off-by: Rafael G. Ruiz <[email protected]>
  • Loading branch information
Razaloc committed Nov 23, 2021
1 parent 5d93072 commit c5c3bdc
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 6 deletions.
5 changes: 5 additions & 0 deletions rust/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ pub mod ffi {
fn get_packages_local(&self) -> Vec<String>;
fn get_packages_local_fileoverride(&self) -> Vec<String>;
fn get_packages_override_replace_local(&self) -> Vec<String>;
fn get_packages_override_replace(&self) -> Vec<String>;
fn get_packages_override_remove(&self) -> Vec<String>;
fn get_modules_enable(&self) -> Vec<String>;
fn get_modules_install(&self) -> Vec<String>;
Expand Down
7 changes: 6 additions & 1 deletion rust/src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -60,6 +61,7 @@ pub(crate) fn origin_to_treefile_inner(kf: &KeyFile) -> Result<Box<Treefile>> {
}
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")
Expand Down Expand Up @@ -163,6 +165,9 @@ fn treefile_to_origin_inner(tf: &Treefile) -> Result<glib::KeyFile> {
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());
Expand Down
13 changes: 12 additions & 1 deletion rust/src/treefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,15 @@ impl Treefile {
.map(|(k, v)| format!("{}:{}", v, k))
.collect()
}

pub(crate) fn get_packages_override_replace(&self) -> Vec<String> {
self.parsed
.derive
.override_replace
.iter()
.flatten()
.map(|(k, v)| format!("{}:{}", v, k))
.collect()
}
pub(crate) fn get_exclude_packages(&self) -> Vec<String> {
self.parsed.exclude_packages.clone().unwrap_or_default()
}
Expand Down Expand Up @@ -1363,6 +1371,8 @@ pub(crate) struct DeriveConfigFields {
pub(crate) override_remove: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) override_replace_local: Option<BTreeMap<String, String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) override_replace: Option<BTreeMap<String, String>>,

// Initramfs
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -1393,6 +1403,7 @@ impl DeriveConfigFields {
check!(packages_local_fileoverride);
check!(override_remove);
check!(override_replace_local);
check!(override_replace);
check!(initramfs);
check!(custom);
Ok(())
Expand Down
11 changes: 11 additions & 0 deletions src/app/rpmostree-builtin-status.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/libpriv/rpmostree-core.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
48 changes: 45 additions & 3 deletions src/libpriv/rpmostree-origin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
};
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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++)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1007,19 +1021,28 @@ 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)
g_hash_table_insert (origin->cached_overrides_local_replace, g_strdup (pkg),
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 ();

Expand All @@ -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);
Expand All @@ -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))
Expand All @@ -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);
Expand All @@ -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;
}
5 changes: 4 additions & 1 deletion src/libpriv/rpmostree-origin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c5c3bdc

Please sign in to comment.