Skip to content

Commit

Permalink
kargs: Simplify idempotent append and delete operations
Browse files Browse the repository at this point in the history
Simplify idempotent operations; this allows us to drop
the `existing_kargs` variable.
Fixes the corner case where `--append foo --append-if-missing foo`
would append `foo` twice.

This uses the new libostree OstreeKernelArgs API symbols, so
we bump the libostree version requirement.

Signed-off-by: Rafael Garcia Ruiz <rafael.garcia@collabora.com>
  • Loading branch information
Razaloc authored and cgwalters committed May 2, 2023
1 parent 3670b45 commit 1a1ef13
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ PKG_PROG_PKG_CONFIG
dnl Remember to update AM_CPPFLAGS in Makefile.am when bumping GIO req.
PKG_CHECK_MODULES(PKGDEP_GIO_UNIX, [gio-unix-2.0])
dnl These are the dependencies of the public librpmostree-1.0.0 shared library
PKG_CHECK_MODULES(PKGDEP_LIBRPMOSTREE, [gio-unix-2.0 >= 2.50.0 json-glib-1.0 ostree-1 >= 2021.2 rpm >= 4.16])
PKG_CHECK_MODULES(PKGDEP_LIBRPMOSTREE, [gio-unix-2.0 >= 2.50.0 json-glib-1.0 ostree-1 >= 2022.7 rpm >= 4.16])
dnl And these additional ones are used by for the rpmostreeinternals C/C++ library
PKG_CHECK_MODULES(PKGDEP_RPMOSTREE, [polkit-gobject-1 libarchive])

Expand Down
9 changes: 4 additions & 5 deletions src/daemon/rpmostreed-transaction-types.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2679,7 +2679,6 @@ kernel_arg_apply_patching (KernelArgTransaction *self, RpmOstreeSysrootUpgrader
= static_cast<char **> (vardict_lookup_strv_canonical (self->options, "append-if-missing"));
g_autofree char **delete_if_present
= static_cast<char **> (vardict_lookup_strv_canonical (self->options, "delete-if-present"));
g_auto (GStrv) existing_kargs = g_strsplit (self->existing_kernel_args, " ", -1);
gboolean changed = FALSE;

/* Delete all the entries included in the kernel args */
Expand Down Expand Up @@ -2708,19 +2707,19 @@ kernel_arg_apply_patching (KernelArgTransaction *self, RpmOstreeSysrootUpgrader
for (char **iter = append_if_missing; iter && *iter; iter++)
{
const char *arg = *iter;
if (!g_strv_contains (existing_kargs, arg))
if (!ostree_kernel_args_contains (kargs, arg))
{
ostree_kernel_args_append (kargs, arg);
ostree_kernel_args_append_if_missing (kargs, arg);
changed = TRUE;
}
}

for (char **iter = delete_if_present; iter && *iter; iter++)
{
const char *arg = *iter;
if (g_strv_contains (existing_kargs, arg))
if (ostree_kernel_args_contains (kargs, arg))
{
if (!ostree_kernel_args_delete (kargs, arg, error))
if (!ostree_kernel_args_delete_if_present (kargs, arg, error))
return FALSE;
changed = TRUE;
}
Expand Down

0 comments on commit 1a1ef13

Please sign in to comment.