diff --git a/src/daemon/rpmostreed-transaction-types.cxx b/src/daemon/rpmostreed-transaction-types.cxx index b0c4030a7d..be4bb3e393 100644 --- a/src/daemon/rpmostreed-transaction-types.cxx +++ b/src/daemon/rpmostreed-transaction-types.cxx @@ -2679,6 +2679,9 @@ kernel_arg_apply_patching (KernelArgTransaction *self, RpmOstreeSysrootUpgrader = static_cast (vardict_lookup_strv_canonical (self->options, "append-if-missing")); g_autofree char **delete_if_present = static_cast (vardict_lookup_strv_canonical (self->options, "delete-if-present")); + g_autoptr (OstreeKernelArgs) existing_kargs + = ostree_kernel_args_from_string (self->existing_kernel_args); + g_auto (GStrv) existing_kargs_strv = ostree_kernel_args_to_strv (existing_kargs); gboolean changed = FALSE; /* Delete all the entries included in the kernel args */ @@ -2707,9 +2710,10 @@ kernel_arg_apply_patching (KernelArgTransaction *self, RpmOstreeSysrootUpgrader for (char **iter = append_if_missing; iter && *iter; iter++) { const char *arg = *iter; - if (!ostree_kernel_args_contains (kargs, arg)) + g_auto (GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs); + if (!g_strv_contains (kargs_strv, arg)) { - ostree_kernel_args_append_if_missing (kargs, arg); + ostree_kernel_args_append (kargs, arg); changed = TRUE; } } @@ -2717,9 +2721,9 @@ kernel_arg_apply_patching (KernelArgTransaction *self, RpmOstreeSysrootUpgrader for (char **iter = delete_if_present; iter && *iter; iter++) { const char *arg = *iter; - if (ostree_kernel_args_contains (kargs, arg)) + if (g_strv_contains (existing_kargs_strv, arg)) { - if (!ostree_kernel_args_delete_if_present (kargs, arg, error)) + if (!ostree_kernel_args_delete (kargs, arg, error)) return FALSE; changed = TRUE; } diff --git a/tests/vmcheck/test-kernel-args.sh b/tests/vmcheck/test-kernel-args.sh index d48b393bf6..e66373cfc6 100755 --- a/tests/vmcheck/test-kernel-args.sh +++ b/tests/vmcheck/test-kernel-args.sh @@ -178,6 +178,28 @@ vm_rpmostree kargs --delete-if-present=PACKAGE3=TEST3 --unchanged-exit-77 || rc= assert_streq $rc 77 echo "ok exit 77 when unchanged kargs with unchanged-exit-77" +# Test append-if-missing and delete-if-present for existing key +vm_rpmostree kargs --append-if-missing=PACKAGE4=TEST4 +vm_rpmostree kargs > kargs.txt +assert_file_has_content_literal kargs.txt 'PACKAGE4=TEST4' +vm_rpmostree kargs --append-if-missing=PACKAGE4=NEWTEST +vm_rpmostree kargs > kargs.txt +assert_file_has_content_literal kargs.txt 'PACKAGE4=NEWTEST' +vm_rpmostree kargs --delete-if-present=PACKAGE4=TEST --unchanged-exit-77 || rc=$? +assert_streq $rc 77 +echo "ok for append-if-missing and delete-if-present with existing key" + +# Test corner case for append and append-if-missing with the same value +vm_rpmostree kargs --append=foo --append-if-missing=foo +vm_rpmostree kargs > kargs.txt +assert_not_file_has_content_literal kargs.txt 'foo foo' +assert_file_has_content_literal kargs.txt 'foo' +vm_rpmostree kargs --append-if-missing=bar=foo --append-if-missing=bar=foo +vm_rpmostree kargs > kargs.txt +assert_not_file_has_content_literal kargs.txt 'bar=foo bar=foo' +assert_file_has_content_literal kargs.txt 'bar=foo' +echo "ok for append and append-if-missing with the same value" + # Test for 'rpm-ostree kargs --editor'. vm_rpmostree kargs > kargs.txt assert_not_file_has_content_literal kargs.txt 'nonexisting'