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 Oct 17, 2021
1 parent 7b5b210 commit 67566d2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
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 67566d2

Please sign in to comment.