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
This commit is contained in:
Matthew Leeds authored and Atomic Bot committed 2019-03-01 16:29:44 +00:00
1 parent 77f91d6c6b
commit eecd989d46
3 files changed
+94 -5

No files matched your search

+42 -1
View File
@@ -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,