diff options
author | Thomas Haller <thaller@redhat.com> | 2019-12-19 09:54:09 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-12-21 12:36:36 +0100 |
commit | 32033d908622da573ad4c14e33ce4a48c8e6d36c (patch) | |
tree | 06d0b70fb24f5541e43087c5c00e9f242fabfd96 | |
parent | 89d8b254eb794ff3b48fe339a26f46f1afbf54e2 (diff) | |
download | NetworkManager-32033d908622da573ad4c14e33ce4a48c8e6d36c.tar.gz |
ifcfg-rh: mark lines as non-dirty in shvarFile when we visit them
By default, all lines are now marked as dirty. Whenever we modify/set
a line, it becomes non-dirty. That will be used later to prune lines
that are dirty, that is, not yet visited.
-rw-r--r-- | src/settings/plugins/ifcfg-rh/shvar.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 16b2dd3762..c58b23f8df 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -45,6 +45,9 @@ struct _shvarLine { char *line; const char *key; char *key_with_prefix; + + /* svSetValue() will clear the dirty flag. */ + bool dirty:1; }; typedef struct _shvarLine shvarLine; @@ -671,8 +674,11 @@ line_new_parse (const char *value, gsize len) nm_assert (value); - line = g_slice_new0 (shvarLine); - c_list_init (&line->lst); + line = g_slice_new (shvarLine); + *line = (shvarLine) { + .lst = C_LIST_INIT (line->lst), + .dirty = TRUE, + }; for (k = 0; k < len; k++) { if (g_ascii_isspace (value[k])) @@ -706,14 +712,19 @@ line_new_build (const char *key, const char *value) { char *value_escaped = NULL; shvarLine *line; + char *new_key; value = svEscape (value, &value_escaped); line = g_slice_new (shvarLine); - c_list_init (&line->lst); - line->line = value_escaped ?: g_strdup (value); - line->key_with_prefix = g_strdup (key); - line->key = line->key_with_prefix; + new_key = g_strdup (key), + *line = (shvarLine) { + .lst = C_LIST_INIT (line->lst), + .line = value_escaped ?: g_strdup (value), + .key_with_prefix = new_key, + .key = new_key, + .dirty = FALSE, + }; ASSERT_shvarLine (line); return line; } @@ -727,6 +738,8 @@ line_set (shvarLine *line, const char *value) ASSERT_shvarLine (line); nm_assert (line->key); + line->dirty = FALSE; + if (line->key != line->key_with_prefix) { memmove (line->key_with_prefix, line->key, strlen (line->key) + 1); line->key = line->key_with_prefix; @@ -1284,6 +1297,8 @@ svSetValue (shvarFile *s, const char *key, const char *value) if (!value) { if (line) { + /* We only clear the value, but leave the line entry. This way, if we + * happen to re-add the value, we write it to the same line again. */ if (nm_clear_g_free (&line->line)) { changed = TRUE; } |