cmdline: Start conversion to new code style

This is just a few.  I'm tempted to try out the coccinelle
patch for this.

Closes: #793
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-04-14 10:26:35 -04:00 committed by Atomic Bot
parent d197bfd133
commit 0d8cd2f077
3 changed files with 32 additions and 71 deletions

View File

@ -35,7 +35,6 @@ static GOptionEntry options[] = {
gboolean gboolean
ot_admin_builtin_undeploy (int argc, char **argv, GCancellable *cancellable, GError **error) ot_admin_builtin_undeploy (int argc, char **argv, GCancellable *cancellable, GError **error)
{ {
gboolean ret = FALSE;
g_autoptr(GOptionContext) context = NULL; g_autoptr(GOptionContext) context = NULL;
glnx_unref_object OstreeSysroot *sysroot = NULL; glnx_unref_object OstreeSysroot *sysroot = NULL;
const char *deploy_index_str; const char *deploy_index_str;
@ -48,16 +47,16 @@ ot_admin_builtin_undeploy (int argc, char **argv, GCancellable *cancellable, GEr
if (!ostree_admin_option_context_parse (context, options, &argc, &argv, if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
&sysroot, cancellable, error)) &sysroot, cancellable, error))
goto out; return FALSE;
if (argc < 2) if (argc < 2)
{ {
ot_util_usage_error (context, "INDEX must be specified", error); ot_util_usage_error (context, "INDEX must be specified", error);
goto out; return FALSE;
} }
if (!ostree_sysroot_load (sysroot, cancellable, error)) if (!ostree_sysroot_load (sysroot, cancellable, error))
goto out; return FALSE;
current_deployments = ostree_sysroot_get_deployments (sysroot); current_deployments = ostree_sysroot_get_deployments (sysroot);
deploy_index_str = argv[1]; deploy_index_str = argv[1];
@ -65,31 +64,26 @@ ot_admin_builtin_undeploy (int argc, char **argv, GCancellable *cancellable, GEr
target_deployment = ot_admin_get_indexed_deployment (sysroot, deploy_index, error); target_deployment = ot_admin_get_indexed_deployment (sysroot, deploy_index, error);
if (!target_deployment) if (!target_deployment)
goto out; return FALSE;
if (target_deployment == ostree_sysroot_get_booted_deployment (sysroot)) if (target_deployment == ostree_sysroot_get_booted_deployment (sysroot))
{ {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
"Cannot undeploy currently booted deployment %i", deploy_index); "Cannot undeploy currently booted deployment %i", deploy_index);
goto out; return FALSE;
} }
g_ptr_array_remove_index (current_deployments, deploy_index); g_ptr_array_remove_index (current_deployments, deploy_index);
if (!ostree_sysroot_write_deployments (sysroot, current_deployments, if (!ostree_sysroot_write_deployments (sysroot, current_deployments,
cancellable, error)) cancellable, error))
goto out; return FALSE;
g_print ("Deleted deployment %s.%d\n", ostree_deployment_get_csum (target_deployment), g_print ("Deleted deployment %s.%d\n", ostree_deployment_get_csum (target_deployment),
ostree_deployment_get_deployserial (target_deployment)); ostree_deployment_get_deployserial (target_deployment));
if (!ostree_sysroot_cleanup (sysroot, cancellable, error))
{
g_prefix_error (error, "Performing final cleanup: ");
goto out;
}
ret = TRUE; if (!ostree_sysroot_cleanup (sysroot, cancellable, error))
out: return g_prefix_error (error, "Performing final cleanup: "), FALSE;
return ret;
return TRUE;
} }

View File

@ -33,20 +33,11 @@ ot_admin_require_booted_deployment_or_osname (OstreeSysroot *sysroot,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
OstreeDeployment *booted_deployment = OstreeDeployment *booted_deployment =
ostree_sysroot_get_booted_deployment (sysroot); ostree_sysroot_get_booted_deployment (sysroot);
if (booted_deployment == NULL && osname == NULL) if (booted_deployment == NULL && osname == NULL)
{ return glnx_throw (error, "Not currently booted into an OSTree system and no --os= argument given");
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, return TRUE;
"Not currently booted into an OSTree system and no --os= argument given");
goto out;
}
ret = TRUE;
out:
return ret;
} }
/** /**
@ -141,7 +132,7 @@ ot_admin_sysroot_lock (OstreeSysroot *sysroot,
g_source_set_callback (timeout_src, (GSourceFunc)on_sysroot_lock_timeout, &state, NULL); g_source_set_callback (timeout_src, (GSourceFunc)on_sysroot_lock_timeout, &state, NULL);
g_source_attach (timeout_src, state.mainctx); g_source_attach (timeout_src, state.mainctx);
g_source_unref (timeout_src); g_source_unref (timeout_src);
on_sysroot_lock_timeout (&state); on_sysroot_lock_timeout (&state);
ostree_sysroot_lock_async (sysroot, NULL, (GAsyncReadyCallback)on_sysroot_lock_acquired, &state); ostree_sysroot_lock_async (sysroot, NULL, (GAsyncReadyCallback)on_sysroot_lock_acquired, &state);
@ -161,14 +152,11 @@ gboolean
ot_admin_execve_reboot (OstreeSysroot *sysroot, GError **error) ot_admin_execve_reboot (OstreeSysroot *sysroot, GError **error)
{ {
g_autoptr(GFile) real_sysroot = g_file_new_for_path ("/"); g_autoptr(GFile) real_sysroot = g_file_new_for_path ("/");
if (g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot)) if (g_file_equal (ostree_sysroot_get_path (sysroot), real_sysroot))
{ {
if (execlp ("systemctl", "systemctl", "reboot", NULL) < 0) if (execlp ("systemctl", "systemctl", "reboot", NULL) < 0)
{ return glnx_throw_errno (error);
glnx_set_error_from_errno (error);
return FALSE;
}
} }
return TRUE; return TRUE;

View File

@ -223,7 +223,6 @@ ostree_option_context_parse (GOptionContext *context,
GError **error) GError **error)
{ {
glnx_unref_object OstreeRepo *repo = NULL; glnx_unref_object OstreeRepo *repo = NULL;
gboolean success = FALSE;
/* Entries are listed in --help output in the order added. We add the /* Entries are listed in --help output in the order added. We add the
* main entries ourselves so that we can add the --repo entry first. */ * main entries ourselves so that we can add the --repo entry first. */
@ -278,7 +277,7 @@ ostree_option_context_parse (GOptionContext *context,
{ {
g_propagate_error (error, g_steal_pointer (&local_error)); g_propagate_error (error, g_steal_pointer (&local_error));
} }
goto out; return FALSE;
} }
} }
else if (opt_repo != NULL) else if (opt_repo != NULL)
@ -289,17 +288,14 @@ ostree_option_context_parse (GOptionContext *context,
if (!(flags & OSTREE_BUILTIN_FLAG_NO_CHECK)) if (!(flags & OSTREE_BUILTIN_FLAG_NO_CHECK))
{ {
if (!ostree_repo_open (repo, cancellable, error)) if (!ostree_repo_open (repo, cancellable, error))
goto out; return FALSE;
} }
} }
if (out_repo) if (out_repo)
*out_repo = g_steal_pointer (&repo); *out_repo = g_steal_pointer (&repo);
success = TRUE; return TRUE;
out:
return success;
} }
gboolean gboolean
@ -312,22 +308,19 @@ ostree_admin_option_context_parse (GOptionContext *context,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
g_autoptr(GFile) sysroot_path = NULL;
glnx_unref_object OstreeSysroot *sysroot = NULL;
gboolean success = FALSE;
/* Entries are listed in --help output in the order added. We add the /* Entries are listed in --help output in the order added. We add the
* main entries ourselves so that we can add the --sysroot entry first. */ * main entries ourselves so that we can add the --sysroot entry first. */
g_option_context_add_main_entries (context, global_admin_entries, NULL); g_option_context_add_main_entries (context, global_admin_entries, NULL);
if (!ostree_option_context_parse (context, main_entries, argc, argv, OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, error)) if (!ostree_option_context_parse (context, main_entries, argc, argv, OSTREE_BUILTIN_FLAG_NO_REPO, NULL, cancellable, error))
goto out; return FALSE;
g_autoptr(GFile) sysroot_path = NULL;
if (opt_sysroot != NULL) if (opt_sysroot != NULL)
sysroot_path = g_file_new_for_path (opt_sysroot); sysroot_path = g_file_new_for_path (opt_sysroot);
sysroot = ostree_sysroot_new (sysroot_path); glnx_unref_object OstreeSysroot *sysroot = ostree_sysroot_new (sysroot_path);
if (flags & OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER) if (flags & OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER)
{ {
@ -338,7 +331,7 @@ ostree_admin_option_context_parse (GOptionContext *context,
{ {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED, g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
"You must be root to perform this command"); "You must be root to perform this command");
goto out; return FALSE;
} }
} }
@ -350,15 +343,11 @@ ostree_admin_option_context_parse (GOptionContext *context,
g_autofree char *deployment_path = NULL; g_autofree char *deployment_path = NULL;
if (!ostree_sysroot_load (sysroot, cancellable, error)) if (!ostree_sysroot_load (sysroot, cancellable, error))
goto out; return FALSE;
deployments = ostree_sysroot_get_deployments (sysroot); deployments = ostree_sysroot_get_deployments (sysroot);
if (deployments->len == 0) if (deployments->len == 0)
{ return glnx_throw (error, "Unable to find a deployment in sysroot");
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Unable to find a deployment in sysroot");
goto out;
}
first_deployment = deployments->pdata[0]; first_deployment = deployments->pdata[0];
deployment_file = ostree_sysroot_get_deployment_directory (sysroot, first_deployment); deployment_file = ostree_sysroot_get_deployment_directory (sysroot, first_deployment);
deployment_path = g_file_get_path (deployment_file); deployment_path = g_file_get_path (deployment_file);
@ -379,29 +368,22 @@ ostree_admin_option_context_parse (GOptionContext *context,
{ {
/* Released when sysroot is finalized, or on process exit */ /* Released when sysroot is finalized, or on process exit */
if (!ot_admin_sysroot_lock (sysroot, error)) if (!ot_admin_sysroot_lock (sysroot, error))
goto out; return FALSE;
} }
if (out_sysroot) if (out_sysroot)
*out_sysroot = g_steal_pointer (&sysroot); *out_sysroot = g_steal_pointer (&sysroot);
success = TRUE; return TRUE;
out:
return success;
} }
gboolean gboolean
ostree_ensure_repo_writable (OstreeRepo *repo, ostree_ensure_repo_writable (OstreeRepo *repo,
GError **error) GError **error)
{ {
gboolean ret; if (!ostree_repo_is_writable (repo, error))
return g_prefix_error (error, "Cannot write to repository: "), FALSE;
ret = ostree_repo_is_writable (repo, error); return TRUE;
g_prefix_error (error, "Cannot write to repository: ");
return ret;
} }
void void
@ -432,7 +414,6 @@ ostree_print_gpg_verify_result (OstreeGpgVerifyResult *result)
gboolean gboolean
ot_enable_tombstone_commits (OstreeRepo *repo, GError **error) ot_enable_tombstone_commits (OstreeRepo *repo, GError **error)
{ {
gboolean ret = FALSE;
gboolean tombstone_commits = FALSE; gboolean tombstone_commits = FALSE;
GKeyFile *config = ostree_repo_get_config (repo); GKeyFile *config = ostree_repo_get_config (repo);
@ -442,10 +423,8 @@ ot_enable_tombstone_commits (OstreeRepo *repo, GError **error)
{ {
g_key_file_set_boolean (config, "core", "tombstone-commits", TRUE); g_key_file_set_boolean (config, "core", "tombstone-commits", TRUE);
if (!ostree_repo_write_config (repo, config, error)) if (!ostree_repo_write_config (repo, config, error))
goto out; return FALSE;
} }
ret = TRUE; return TRUE;
out:
return ret;
} }