ostree/config: Use g_autoptr instead of goto
It seems cleaner to make the GKeyFile a g_autoptr variable and just return rather than using the "goto out;" idiom. Closes: #1743 Approved by: cgwalters
This commit is contained in:
parent
eecd989d46
commit
fe6b197516
|
|
@ -65,23 +65,22 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
|
||||||
{
|
{
|
||||||
g_autoptr(GOptionContext) context = NULL;
|
g_autoptr(GOptionContext) context = NULL;
|
||||||
g_autoptr(OstreeRepo) repo = NULL;
|
g_autoptr(OstreeRepo) repo = NULL;
|
||||||
gboolean ret = FALSE;
|
|
||||||
const char *op;
|
const char *op;
|
||||||
const char *section_key;
|
const char *section_key;
|
||||||
const char *value;
|
const char *value;
|
||||||
g_autofree char *section = NULL;
|
g_autofree char *section = NULL;
|
||||||
g_autofree char *key = NULL;
|
g_autofree char *key = NULL;
|
||||||
GKeyFile *config = NULL;
|
g_autoptr(GKeyFile) config = NULL;
|
||||||
|
|
||||||
context = g_option_context_new ("(get KEY|set KEY VALUE|unset KEY)");
|
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))
|
if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
ot_util_usage_error (context, "OPERATION must be specified", error);
|
ot_util_usage_error (context, "OPERATION must be specified", error);
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
op = argv[1];
|
op = argv[1];
|
||||||
|
|
@ -94,7 +93,7 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
"GROUP name, KEY and VALUE must be specified");
|
"GROUP name, KEY and VALUE must be specified");
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
section = g_strdup(opt_group);
|
section = g_strdup(opt_group);
|
||||||
key = g_strdup(argv[2]);
|
key = g_strdup(argv[2]);
|
||||||
|
|
@ -106,19 +105,19 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
"KEY and VALUE must be specified");
|
"KEY and VALUE must be specified");
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
section_key = argv[2];
|
section_key = argv[2];
|
||||||
value = argv[3];
|
value = argv[3];
|
||||||
if(!split_key_string (section_key, §ion, &key, error))
|
if(!split_key_string (section_key, §ion, &key, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
config = ostree_repo_copy_config (repo);
|
config = ostree_repo_copy_config (repo);
|
||||||
g_key_file_set_string (config, section, key, value);
|
g_key_file_set_string (config, section, key, value);
|
||||||
|
|
||||||
if (!ostree_repo_write_config (repo, config, error))
|
if (!ostree_repo_write_config (repo, config, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
else if (!strcmp (op, "get"))
|
else if (!strcmp (op, "get"))
|
||||||
{
|
{
|
||||||
|
|
@ -130,7 +129,7 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
"Group name and key must be specified");
|
"Group name and key must be specified");
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
section = g_strdup(opt_group);
|
section = g_strdup(opt_group);
|
||||||
key = g_strdup(argv[2]);
|
key = g_strdup(argv[2]);
|
||||||
|
|
@ -141,17 +140,17 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
"KEY must be specified");
|
"KEY must be specified");
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
section_key = argv[2];
|
section_key = argv[2];
|
||||||
if (!split_key_string (section_key, §ion, &key, error))
|
if (!split_key_string (section_key, §ion, &key, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly_config = ostree_repo_get_config (repo);
|
readonly_config = ostree_repo_get_config (repo);
|
||||||
value = g_key_file_get_string (readonly_config, section, key, error);
|
value = g_key_file_get_string (readonly_config, section, key, error);
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
goto out;
|
return FALSE;
|
||||||
|
|
||||||
g_print ("%s\n", value);
|
g_print ("%s\n", value);
|
||||||
}
|
}
|
||||||
|
|
@ -164,7 +163,7 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
"Group name and key must be specified");
|
"Group name and key must be specified");
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
section = g_strdup(opt_group);
|
section = g_strdup(opt_group);
|
||||||
key = g_strdup(argv[2]);
|
key = g_strdup(argv[2]);
|
||||||
|
|
@ -175,11 +174,11 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
"KEY must be specified");
|
"KEY must be specified");
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
section_key = argv[2];
|
section_key = argv[2];
|
||||||
if (!split_key_string (section_key, §ion, &key, error))
|
if (!split_key_string (section_key, §ion, &key, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
config = ostree_repo_copy_config (repo);
|
config = ostree_repo_copy_config (repo);
|
||||||
|
|
@ -189,23 +188,19 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
|
||||||
!g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_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));
|
g_propagate_error (error, g_steal_pointer (&local_error));
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (local_error == NULL && !ostree_repo_write_config (repo, config, error))
|
if (local_error == NULL && !ostree_repo_write_config (repo, config, error))
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
"Unknown operation %s", op);
|
"Unknown operation %s", op);
|
||||||
goto out;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = TRUE;
|
return TRUE;
|
||||||
out:
|
|
||||||
if (config)
|
|
||||||
g_key_file_free (config);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue