Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kargs: run delete-if-present and append-if-missing failed when there is existing key #4738

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/daemon/rpmostreed-transaction-types.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2679,6 +2679,9 @@ 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_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 */
Expand Down Expand Up @@ -2707,19 +2710,20 @@ 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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be cleaner with an ostree_kernel_args_contains_value which doesn't strip off the value.

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;
}
}

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;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/vmcheck/test-kernel-args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down