ostree_kernel_args_contains for OstreeKernelArgs

Check if an argument is present in OstreeKernelArgs. This is a way to
make easier idempotent append and delete operations.
ostree_kernel_args_append_if_missing uses it to avoid inserting a
duplicate key.

Closes #2329

Signed-off-by: Rafael Garcia Ruiz <rafael.garcia@collabora.com>
This commit is contained in:
Rafael Garcia Ruiz committed 2022-11-18 13:52:08 +01:00
1 parent 0dbd87c017
commit c4db171dae
6 files changed
+41 -7

No files matched your search

+4
View File
@@ -20,6 +20,10 @@
- uncomment the include in Makefile-libostree.am
*/
LIBOSTREE_2022.7 {
global:
ostree_kernel_args_contains;
} LIBOSTREE_2022.5;
/* Stub section for the stable release *after* this development one; don't
* edit this other than to update the year. This is just a copy/paste
+23 -4
View File
@@ -820,12 +820,31 @@ void
ostree_kernel_args_append_if_missing (OstreeKernelArgs *kargs,
const char *arg)
{
g_autofree char *key = g_strdup (arg);
split_keyeq (key);
// Don't insert a duplicate key.
if (g_hash_table_contains (kargs->table, key))
if (ostree_kernel_args_contains (kargs, arg))
return;
ostree_kernel_args_append (kargs, arg);
}
/**
* ostree_kernel_args_contains:
* @kargs: a OstreeKernelArgs instance
* @arg: key or key/value pair to check
*
* Search for @arg which is in the form of key=value pair at the hash table kargs->table
* and returns true if finds it.
*
*Returns: %TRUE if @arg is contained in @kargs, %FALSE otherwise.
*
* Since: 2022.7
**/
gboolean
ostree_kernel_args_contains (OstreeKernelArgs *kargs,
const char *arg)
{
g_autofree char *key = g_strdup (arg);
split_keyeq (key);
return g_hash_table_contains (kargs->table, key);
}
+4
View File
@@ -134,4 +134,8 @@ _OSTREE_PUBLIC
void ostree_kernel_args_append_if_missing (OstreeKernelArgs *kargs,
const char *arg);
_OSTREE_PUBLIC
gboolean ostree_kernel_args_contains (OstreeKernelArgs *kargs,
const char *arg);
G_END_DECLS