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 <llerrak@hotmail.com>
  • Loading branch information
Razaloc committed Oct 19, 2021
1 parent 7b5b210 commit e87b229
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 5 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 @@ -355,6 +355,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
10 changes: 9 additions & 1 deletion rust/src/treefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,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
11 changes: 11 additions & 0 deletions src/app/rpmostree-builtin-status.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,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 @@ -597,6 +599,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 @@ -936,6 +943,10 @@ print_one_deployment (RPMOSTreeSysroot *sysroot_proxy,
if (str->len)
rpmostree_print_kv ("ReplacedBasePackages", max_key_len, str->str);
}
// 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 @@ -308,6 +314,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 @@ -386,6 +398,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 @@ -430,6 +443,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 @@ -1029,19 +1043,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 @@ -1053,6 +1076,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 @@ -1076,6 +1102,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 @@ -1097,6 +1132,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 @@ -1107,7 +1146,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 @@ -95,6 +95,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 @@ -206,7 +209,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 e87b229

Please sign in to comment.