From f6d308f130c0ca52e1e5d2d951e3f3a5f00c569c Mon Sep 17 00:00:00 2001 From: Rafael Garcia Ruiz Date: Fri, 18 Nov 2022 18:24:01 +0100 Subject: [PATCH] Idempotent delete operation for OstreeKernelArgs ostree_kernel_args_delete_if_present checks if an argument is present in OstreeKernelArgs and delete it. Signed-off-by: Rafael Garcia Ruiz --- apidoc/ostree-sections.txt | 1 + rust-bindings/sys/src/lib.rs | 7 +++++++ src/libostree/libostree-devel.sym | 1 + src/libostree/ostree-kernel-args.c | 22 ++++++++++++++++++++++ src/libostree/ostree-kernel-args.h | 4 ++++ 5 files changed, 35 insertions(+) diff --git a/apidoc/ostree-sections.txt b/apidoc/ostree-sections.txt index d9f91208..49f2748b 100644 --- a/apidoc/ostree-sections.txt +++ b/apidoc/ostree-sections.txt @@ -739,6 +739,7 @@ ostree_kernel_args_from_string ostree_kernel_args_to_strv ostree_kernel_args_to_string ostree_kernel_args_contains +ostree_kernel_args_delete_if_present
diff --git a/rust-bindings/sys/src/lib.rs b/rust-bindings/sys/src/lib.rs index df245a6c..943914ab 100644 --- a/rust-bindings/sys/src/lib.rs +++ b/rust-bindings/sys/src/lib.rs @@ -1319,6 +1319,13 @@ extern "C" { kargs: *mut OstreeKernelArgs, arg: *const c_char, ) -> gboolean; + #[cfg(any(feature = "v2022_7", feature = "dox"))] + #[cfg_attr(feature = "dox", doc(cfg(feature = "v2022_7")))] + pub fn ostree_kernel_args_delete_if_present( + kargs: *mut OstreeKernelArgs, + arg: *const c_char, + error: *mut *mut glib::GError, + ) -> gboolean; #[cfg(any(feature = "v2019_3", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2019_3")))] pub fn ostree_kernel_args_append_proc_cmdline( diff --git a/src/libostree/libostree-devel.sym b/src/libostree/libostree-devel.sym index 2926fe62..6a82433a 100644 --- a/src/libostree/libostree-devel.sym +++ b/src/libostree/libostree-devel.sym @@ -23,6 +23,7 @@ LIBOSTREE_2022.7 { global: ostree_kernel_args_contains; + ostree_kernel_args_delete_if_present; } LIBOSTREE_2022.5; /* Stub section for the stable release *after* this development one; don't diff --git a/src/libostree/ostree-kernel-args.c b/src/libostree/ostree-kernel-args.c index b5fe4def..d15d28a7 100644 --- a/src/libostree/ostree-kernel-args.c +++ b/src/libostree/ostree-kernel-args.c @@ -848,3 +848,25 @@ ostree_kernel_args_contains (OstreeKernelArgs *kargs, return g_hash_table_contains (kargs->table, key); } + +/** + * ostree_kernel_args_delete_if_present: + * @kargs: a OstreeKernelArgs instance + * @arg: key or key/value pair to be deleted + * @error: an GError instance + * + * Deletes @arg which is in the form of key=value pair from the hash table kargs->table. + * + * Returns: %TRUE on success, %FALSE on failure + * + * Since: 2022.7 + **/ +gboolean +ostree_kernel_args_delete_if_present (OstreeKernelArgs *kargs, + const char *arg, + GError **error) +{ + if (ostree_kernel_args_contains (kargs, arg)) + return ostree_kernel_args_delete (kargs, arg, error); + return TRUE; +} diff --git a/src/libostree/ostree-kernel-args.h b/src/libostree/ostree-kernel-args.h index 94c494f6..6a1aaac1 100644 --- a/src/libostree/ostree-kernel-args.h +++ b/src/libostree/ostree-kernel-args.h @@ -138,4 +138,8 @@ _OSTREE_PUBLIC gboolean ostree_kernel_args_contains (OstreeKernelArgs *kargs, const char *arg); +_OSTREE_PUBLIC +gboolean ostree_kernel_args_delete_if_present (OstreeKernelArgs *kargs, + const char *arg, + GError **error); G_END_DECLS