summaryrefslogtreecommitdiff
path: root/src/ostree/ot-builtin-config.c
diff options
context:
space:
mode:
authorMatthew Leeds <matthew.leeds@endlessm.com>2018-09-28 15:36:49 -0700
committerAtomic Bot <atomic-devel@projectatomic.io>2019-03-01 16:29:44 +0000
commiteecd989d4661f48c51f49565422ef11d1c231371 (patch)
tree9e21e4c80575164e6aa33951c855d8c9c0a8d40e /src/ostree/ot-builtin-config.c
parent77f91d6c6be2d264aa14be9d33c0488dc7e141cc (diff)
downloadostree-eecd989d4661f48c51f49565422ef11d1c231371.tar.gz
ostree/config: Add an "unset" operation
Currently there's a way to set a key to the empty string but there's no way to unset it completely (remove the key from the group). This might be helpful for instance if you want to temporarily set "core.lock-timeout-secs" to a specific value for the duration of one operation and then return it to the default after that operation completes. This commit implements an "unset" operation for the config command, adds a unit test, and updates the man page. Closes: #1743 Approved by: cgwalters
Diffstat (limited to 'src/ostree/ot-builtin-config.c')
-rw-r--r--src/ostree/ot-builtin-config.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/ostree/ot-builtin-config.c b/src/ostree/ot-builtin-config.c
index 4368f50c..913ed66d 100644
--- a/src/ostree/ot-builtin-config.c
+++ b/src/ostree/ot-builtin-config.c
@@ -73,7 +73,7 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
g_autofree char *key = NULL;
GKeyFile *config = NULL;
- context = g_option_context_new ("(get KEY|set KEY VALUE)");
+ context = g_option_context_new ("(get KEY|set KEY VALUE|unset KEY)");
if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error))
goto out;
@@ -155,6 +155,47 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
g_print ("%s\n", value);
}
+ else if (!strcmp (op, "unset"))
+ {
+ g_autoptr(GError) local_error = NULL;
+ if (opt_group)
+ {
+ if (argc < 3)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Group name and key must be specified");
+ goto out;
+ }
+ section = g_strdup(opt_group);
+ key = g_strdup(argv[2]);
+ }
+ else
+ {
+ if (argc < 3)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "KEY must be specified");
+ goto out;
+ }
+ section_key = argv[2];
+ if (!split_key_string (section_key, &section, &key, error))
+ goto out;
+ }
+
+ config = ostree_repo_copy_config (repo);
+ if (!g_key_file_remove_key (config, section, key, &local_error))
+ {
+ if (!g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) &&
+ !g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
+ {
+ g_propagate_error (error, g_steal_pointer (&local_error));
+ goto out;
+ }
+ }
+
+ if (local_error == NULL && !ostree_repo_write_config (repo, config, error))
+ goto out;
+ }
else
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,