Blob Blame History Raw
From f295f543064f1a0b5833fefccd6bb203b3527623 Mon Sep 17 00:00:00 2001
From: Colin Walters <walters@verbum.org>
Date: Sun, 17 Nov 2019 15:51:07 +0000
Subject: [PATCH] kargs: Support --append and --delete simultaneously

Code I wrote for the machine-config-operator expected it to
work, and I don't see a reason not to support it.

See https://github.com/openshift/machine-config-operator/issues/1265
---
 src/app/rpmostree-builtin-kargs.c         |  6 ------
 src/daemon/rpmostreed-transaction-types.c | 20 ++++++++++----------
 tests/vmcheck/test-kernel-args.sh         |  9 +++++++++
 3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/app/rpmostree-builtin-kargs.c b/src/app/rpmostree-builtin-kargs.c
index 359df946..fcfb727a 100644
--- a/src/app/rpmostree-builtin-kargs.c
+++ b/src/app/rpmostree-builtin-kargs.c
@@ -196,12 +196,6 @@ rpmostree_builtin_kargs (int            argc,
                    "Cannot specify both --delete and --replace");
       return FALSE;
     }
-  if (opt_kernel_delete_strings && opt_kernel_append_strings)
-    {
-      g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
-                   "Cannot specify both --delete and --append");
-      return FALSE;
-    }
   if (opt_import_proc_cmdline && opt_deploy_index)
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
diff --git a/src/daemon/rpmostreed-transaction-types.c b/src/daemon/rpmostreed-transaction-types.c
index bc62b6c4..da432b83 100644
--- a/src/daemon/rpmostreed-transaction-types.c
+++ b/src/daemon/rpmostreed-transaction-types.c
@@ -2449,20 +2449,20 @@ kernel_arg_transaction_execute (RpmostreedTransaction *transaction,
             return FALSE;
         }
     }
-  else
+
+  if (self->kernel_args_replaced)
     {
-      if (self->kernel_args_replaced)
+      for (char **iter = self->kernel_args_replaced; iter && *iter; iter++)
         {
-          for (char **iter = self->kernel_args_replaced; iter && *iter; iter++)
-            {
-              const char *arg = *iter;
-              if (!ostree_kernel_args_new_replace (kargs, arg, error))
-                return FALSE;
-            }
+          const char *arg = *iter;
+          if (!ostree_kernel_args_new_replace (kargs, arg, error))
+            return FALSE;
         }
+    }
 
-      if (self->kernel_args_added)
-        ostree_kernel_args_append_argv (kargs, self->kernel_args_added);
+  if (self->kernel_args_added)
+    {
+      ostree_kernel_args_append_argv (kargs, self->kernel_args_added);
     }
 
   /* After all the arguments are processed earlier, we convert it to a string list*/
diff --git a/tests/vmcheck/test-kernel-args.sh b/tests/vmcheck/test-kernel-args.sh
index 570d986a..ca105ae3 100755
--- a/tests/vmcheck/test-kernel-args.sh
+++ b/tests/vmcheck/test-kernel-args.sh
@@ -48,6 +48,15 @@ assert_file_has_content_literal kargs.txt 'FOO=BAR'
 assert_file_has_content_literal kargs.txt 'APPENDARG=VALAPPEND APPENDARG=2NDAPPEND'
 echo "ok kargs append"
 
+# Ensure the result flows through with rpm-ostree kargs
+vm_rpmostree kargs --append=APPENDARG=3RDAPPEND --delete=APPENDARG=VALAPPEND
+vm_rpmostree kargs > kargs.txt
+assert_not_file_has_content kargs.txt 'APPENDARG=VALAPPEND'
+assert_file_has_content_literal kargs.txt 'APPENDARG=3RDAPPEND'
+# And reset to previous state
+vm_rpmostree cleanup -p
+echo "ok kargs append and delete"
+
 # Test for rpm-ostree kargs delete
 vm_kargs_now kargs --delete FOO
 vm_cmd grep ^options /boot/loader/entries/ostree-2-$osname.conf > tmp_conf.txt
-- 
2.24.1