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

Consider a safe way to fix `corner case where --append foo
--append-if-missing foo would append foo twice`.
  • Loading branch information
HuijingHei committed Dec 20, 2023
1 parent 419fc98 commit 8325215
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 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
13 changes: 12 additions & 1 deletion tests/vmcheck/test-kernel-args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,18 @@ vm_rpmostree kargs > kargs.txt
assert_file_has_content_literal kargs.txt 'PACKAGE3=NEWTEST'
rpm-ostree kargs --delete-if-present=PACKAGE3=TEST || rc=$?
assert_streq $rc 0
vm_rpmostree kargs --delete-if-present=PACKAGE3=TEST3
echo "ok for append-if-missing and delete-if-present if 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=PACKAGE4=TEST4 --append-if-missing=PACKAGE4=TEST4
vm_rpmostree kargs > kargs.txt
assert_not_file_has_content_literal kargs.txt 'PACKAGE4=TEST4 PACKAGE4=TEST4'
assert_file_has_content_literal kargs.txt 'PACKAGE4=TEST4'
echo "ok for append and append-if-missing with the same value"

# Test for 'rpm-ostree kargs --editor'.
vm_rpmostree kargs > kargs.txt
Expand Down

0 comments on commit 8325215

Please sign in to comment.