diff options
author | Daniel Playfair Cal <daniel.playfair.cal@gmail.com> | 2019-02-12 22:15:56 +0000 |
---|---|---|
committer | Daniel Playfair Cal <daniel.playfair.cal@gmail.com> | 2019-02-12 22:15:56 +0000 |
commit | 0740fd9c28f5cb2cfab634ebdd3c6f4893e2d296 (patch) | |
tree | 1444a893b63574b768194dce7b5a9b7cc37cc05c /bin/dconf.c | |
parent | f0bb97ded21f8d2fb50065e7cfefade66a70333e (diff) | |
parent | c963f9eec8d72d6e17099d456330cd988294c0af (diff) | |
download | dconf-0740fd9c28f5cb2cfab634ebdd3c6f4893e2d296.tar.gz |
Merge branch 'ignore-non-writable' into 'master'
bin: Add an option to ignore changes to locked keys during load
Closes #1
See merge request GNOME/dconf!43
Diffstat (limited to 'bin/dconf.c')
-rw-r--r-- | bin/dconf.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/bin/dconf.c b/bin/dconf.c index 8e3f060..c91f82a 100644 --- a/bin/dconf.c +++ b/bin/dconf.c @@ -578,14 +578,29 @@ keyfile_foreach (GKeyFile *kf, return TRUE; } +typedef struct { + DConfClient *client; + DConfChangeset *changeset; + gboolean force; +} LoadContext; + static void changeset_set (const gchar *path, GVariant *value, gpointer user_data) { - DConfChangeset *changeset = user_data; + LoadContext *ctx = user_data; + + /* When force option is used, ignore changes made to non-writeable keys to + * avoid rejecting the whole changeset. + */ + if (ctx->force && !dconf_client_is_writable (ctx->client, path)) + { + g_fprintf (stderr, "warning: ignored non-writable key '%s'\n", path); + return; + } - dconf_changeset_set (changeset, path, value); + dconf_changeset_set (ctx->changeset, path, value); } static gboolean @@ -593,27 +608,39 @@ dconf_load (const gchar **argv, GError **error) { const gchar *dir; + gint index = 0; + gboolean force = FALSE; g_autoptr(GError) local_error = NULL; g_autoptr(GKeyFile) kf = NULL; g_autoptr(DConfChangeset) changeset = NULL; g_autoptr (DConfClient) client = NULL; - dir = argv[0]; + if (argv[index] != NULL && strcmp (argv[index], "-f") == 0) + { + force = TRUE; + index += 1; + } + + dir = argv[index]; if (!dconf_is_dir (dir, &local_error)) return option_error_propagate (error, &local_error); - if (argv[1] != NULL) + index += 1; + + if (argv[index] != NULL) return option_error_set (error, "too many arguments"); kf = keyfile_from_stdin (error); if (kf == NULL) return FALSE; + client = dconf_client_new (); changeset = dconf_changeset_new (); - if (!keyfile_foreach (kf, dir, changeset_set, changeset, error)) + + LoadContext ctx = { client, changeset, force }; + if (!keyfile_foreach (kf, dir, changeset_set, &ctx, error)) return FALSE; - client = dconf_client_new (); return dconf_client_change_sync (client, changeset, NULL, NULL, error); } @@ -1024,8 +1051,8 @@ static const Command commands[] = { }, { "load", dconf_load, - "Populate a subpath from stdin", - " DIR " + "Populate a subpath from stdin. -f ignore locked keys.", + " [-f] DIR " }, { "blame", dconf_blame, |