Skip to content

Commit

Permalink
kargs: fix corner case when append and append-if-missing with
Browse files Browse the repository at this point in the history
the same value which will append twice
  • Loading branch information
HuijingHei committed Dec 20, 2023
1 parent acb97c2 commit b5aa8c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/daemon/rpmostreed-transaction-types.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,8 @@ 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))
g_auto (GStrv) kargs_strv = ostree_kernel_args_to_strv (kargs);
if (!g_strv_contains (kargs_strv, arg))
{
ostree_kernel_args_append (kargs, arg);
changed = TRUE;
Expand Down
17 changes: 14 additions & 3 deletions tests/vmcheck/test-kernel-args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,24 @@ echo "ok exit 77 when unchanged kargs with unchanged-exit-77"
vm_rpmostree kargs --append-if-missing=PACKAGE4=TEST4
vm_rpmostree kargs > kargs.txt
assert_file_has_content_literal kargs.txt 'PACKAGE4=TEST4'
rpm-ostree kargs --append-if-missing=PACKAGE4=NEWTEST
vm_rpmostree kargs --append-if-missing=PACKAGE4=NEWTEST
vm_rpmostree kargs > kargs.txt
assert_file_has_content_literal kargs.txt 'PACKAGE4=NEWTEST'
rpm-ostree kargs --delete-if-present=PACKAGE4=TEST || rc=$?
assert_streq $rc 0
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

0 comments on commit b5aa8c3

Please sign in to comment.