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 10, 2021
1 parent 2dd49b5 commit 306216a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/daemon/rpmostreed-transaction-types.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,6 @@ deploy_transaction_execute (RpmostreedTransaction *transaction,
if (vardict_lookup_bool (self->options, "dry-run", FALSE) &&
vardict_lookup_bool (self->options, "download-only", FALSE))
return glnx_throw (error, "Can't specify dry-run and download-only");
if (override_replace_pkgs)
return glnx_throw (error, "Non-local replacement overrides not implemented yet");

if (vardict_lookup_bool (self->options, "no-overrides", FALSE) &&
(override_remove_pkgs || override_reset_pkgs ||
Expand Down
47 changes: 43 additions & 4 deletions src/libpriv/rpmostree-origin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct RpmOstreeOrigin {
GHashTable *cached_modules_enable; /* set of module specs to enable */
GHashTable *cached_modules_install; /* set of module specs to install */
GHashTable *cached_local_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 @@ -115,6 +115,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 @@ -189,6 +191,9 @@ rpmostree_origin_parse_keyfile (GKeyFile *origin,
if (!parse_packages_strv (ret->kf, "overrides", "replace-local", TRUE,
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);
Expand Down Expand Up @@ -313,6 +318,12 @@ rpmostree_origin_get_overrides_local_replace (RpmOstreeOrigin *origin)
return origin->cached_overrides_local_replace;
}

GHashTable *
rpmostree_origin_get_overrides_replace (RpmOstreeOrigin *origin)
{
return origin->cached_overrides_replace;
}

const char *
rpmostree_origin_get_override_commit (RpmOstreeOrigin *origin)
{
Expand Down Expand Up @@ -372,6 +383,7 @@ rpmostree_origin_has_packages (RpmOstreeOrigin *origin)
(g_hash_table_size (origin->cached_packages) > 0) ||
(g_hash_table_size (origin->cached_local_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 @@ -415,6 +427,7 @@ rpmostree_origin_unref (RpmOstreeOrigin *origin)
g_clear_pointer (&origin->cached_modules_install, g_hash_table_unref);
g_clear_pointer (&origin->cached_local_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 @@ -974,17 +987,26 @@ 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_REPLACE)
g_hash_table_insert (origin->cached_overrides_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
Expand All @@ -998,6 +1020,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 @@ -1021,6 +1046,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 @@ -1041,7 +1075,9 @@ 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 @@ -1052,7 +1088,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_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 @@ -202,7 +205,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 306216a

Please sign in to comment.