libnm-glib-aux: move nm_keyfile_add_group()
Move nm_keyfile_add_group() to libnm-glib-aux so that it can be used by other components such as nm-initrd-generator. Rename it to nm_key_file_add_group() to be consistent with the GLib API names (g_key_file_*()).
This commit is contained in:
@@ -682,22 +682,3 @@ nm_keyfile_key_decode(const char *key, char **out_to_free)
|
|||||||
#endif
|
#endif
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
nm_keyfile_add_group(GKeyFile *keyfile, const char *group)
|
|
||||||
{
|
|
||||||
nm_assert(keyfile);
|
|
||||||
nm_assert(group);
|
|
||||||
|
|
||||||
/* You can only call this function if the group doesn't exist yet.
|
|
||||||
* Because, we are about to add a dummy key, so we would have to
|
|
||||||
* be sure that the key doesn't exist. */
|
|
||||||
nm_assert(!g_key_file_has_group(keyfile, group));
|
|
||||||
|
|
||||||
/* Ensure the group is present.
|
|
||||||
* There is no API for that, so add and remove a dummy key.
|
|
||||||
* For a profile it matters whether a setting is present or not,
|
|
||||||
* and we need to ensure that we persist the presence of the setting to keyfile*/
|
|
||||||
g_key_file_set_value(keyfile, group, ".X", "1");
|
|
||||||
g_key_file_remove_key(keyfile, group, ".X", NULL);
|
|
||||||
}
|
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
#include <linux/if_ether.h>
|
#include <linux/if_ether.h>
|
||||||
#include <linux/if_infiniband.h>
|
#include <linux/if_infiniband.h>
|
||||||
|
|
||||||
|
#include "libnm-glib-aux/nm-keyfile-aux.h"
|
||||||
#include "libnm-glib-aux/nm-uuid.h"
|
#include "libnm-glib-aux/nm-uuid.h"
|
||||||
#include "libnm-glib-aux/nm-str-buf.h"
|
#include "libnm-glib-aux/nm-str-buf.h"
|
||||||
#include "libnm-glib-aux/nm-secret-utils.h"
|
#include "libnm-glib-aux/nm-secret-utils.h"
|
||||||
@@ -2502,7 +2503,7 @@ wired_s390_options_writer_full(KeyfileWriterInfo *info,
|
|||||||
/* groups in the keyfile are ordered. When we are about to add [ethernet-s390-options],
|
/* groups in the keyfile are ordered. When we are about to add [ethernet-s390-options],
|
||||||
* we want to also have an [ethernet] group, first. */
|
* we want to also have an [ethernet] group, first. */
|
||||||
|
|
||||||
nm_keyfile_add_group(info->keyfile, setting_alias ?: NM_SETTING_WIRED_SETTING_NAME);
|
nm_key_file_add_group(info->keyfile, setting_alias ?: NM_SETTING_WIRED_SETTING_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
@@ -4475,7 +4476,7 @@ nm_keyfile_write(NMConnection *connection,
|
|||||||
|| g_key_file_has_group(info.keyfile, setting_name)) {
|
|| g_key_file_has_group(info.keyfile, setting_name)) {
|
||||||
/* we have a section for the setting. Nothing to do. */
|
/* we have a section for the setting. Nothing to do. */
|
||||||
} else {
|
} else {
|
||||||
nm_keyfile_add_group(info.keyfile, setting_alias ?: setting_name);
|
nm_key_file_add_group(info.keyfile, setting_alias ?: setting_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NM_IS_SETTING_WIREGUARD(setting)) {
|
if (NM_IS_SETTING_WIREGUARD(setting)) {
|
||||||
|
@@ -88,6 +88,4 @@ const char *nm_keyfile_key_encode(const char *name, char **out_to_free);
|
|||||||
|
|
||||||
const char *nm_keyfile_key_decode(const char *key, char **out_to_free);
|
const char *nm_keyfile_key_decode(const char *key, char **out_to_free);
|
||||||
|
|
||||||
void nm_keyfile_add_group(GKeyFile *keyfile, const char *group);
|
|
||||||
|
|
||||||
#endif /* __NM_KEYFILE_UTILS_H__ */
|
#endif /* __NM_KEYFILE_UTILS_H__ */
|
||||||
|
@@ -485,3 +485,22 @@ nm_key_file_db_prune(NMKeyFileDB *self,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nm_key_file_add_group(GKeyFile *keyfile, const char *group)
|
||||||
|
{
|
||||||
|
nm_assert(keyfile);
|
||||||
|
nm_assert(group);
|
||||||
|
|
||||||
|
/* You can only call this function if the group doesn't exist yet.
|
||||||
|
* Because, we are about to add a dummy key, so we would have to
|
||||||
|
* be sure that the key doesn't exist. */
|
||||||
|
nm_assert(!g_key_file_has_group(keyfile, group));
|
||||||
|
|
||||||
|
/* Ensure the group is present.
|
||||||
|
* There is no API for that, so add and remove a dummy key.
|
||||||
|
* For a profile it matters whether a setting is present or not,
|
||||||
|
* and we need to ensure that we persist the presence of the setting to keyfile*/
|
||||||
|
g_key_file_set_value(keyfile, group, ".X", "1");
|
||||||
|
g_key_file_remove_key(keyfile, group, ".X", NULL);
|
||||||
|
}
|
||||||
|
@@ -58,4 +58,6 @@ void nm_key_file_db_prune(NMKeyFileDB *self,
|
|||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void nm_key_file_add_group(GKeyFile *keyfile, const char *group);
|
||||||
|
|
||||||
#endif /* __NM_KEYFILE_AUX_H__ */
|
#endif /* __NM_KEYFILE_AUX_H__ */
|
||||||
|
Reference in New Issue
Block a user