gboolean
ot_admin_builtin_switch (int argc, char **argv, GCancellable *cancellable, GError **error)
{
- gboolean ret = FALSE;
- g_autoptr(GOptionContext) context = NULL;
+ g_autoptr(GOptionContext) context =
+ g_option_context_new ("REF - Construct new tree from REF and deploy it");
g_autoptr(OstreeSysroot) sysroot = NULL;
- const char *new_provided_refspec = NULL;
- g_autoptr(OstreeRepo) repo = NULL;
- g_autofree char *origin_refspec = NULL;
- g_autofree char *origin_remote = NULL;
- g_autofree char *origin_ref = NULL;
- g_autofree char *new_remote = NULL;
- g_autofree char *new_ref = NULL;
- g_autofree char *new_refspec = NULL;
- const char* remote;
- g_autoptr(OstreeSysrootUpgrader) upgrader = NULL;
- g_autoptr(OstreeAsyncProgress) progress = NULL;
- gboolean changed;
- GKeyFile *old_origin;
- g_autoptr(GKeyFile) new_origin = NULL;
-
- context = g_option_context_new ("REF - Construct new tree from REF and deploy it");
-
if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
&sysroot, cancellable, error))
- goto out;
+ return FALSE;
if (argc < 2)
{
ot_util_usage_error (context, "REF must be specified", error);
- goto out;
+ return FALSE;
}
- new_provided_refspec = argv[1];
+ const char *new_provided_refspec = argv[1];
if (!ostree_sysroot_load (sysroot, cancellable, error))
- goto out;
+ return FALSE;
- upgrader = ostree_sysroot_upgrader_new_for_os_with_flags (sysroot, opt_osname,
- OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED,
- cancellable, error);
+ g_autoptr(OstreeSysrootUpgrader) upgrader =
+ ostree_sysroot_upgrader_new_for_os_with_flags (sysroot, opt_osname,
+ OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED,
+ cancellable, error);
if (!upgrader)
- goto out;
+ return FALSE;
- old_origin = ostree_sysroot_upgrader_get_origin (upgrader);
- origin_refspec = g_key_file_get_string (old_origin, "origin", "refspec", NULL);
-
+ GKeyFile *old_origin = ostree_sysroot_upgrader_get_origin (upgrader);
+ g_autofree char *origin_refspec = g_key_file_get_string (old_origin, "origin", "refspec", NULL);
+ g_autofree char *origin_remote = NULL;
+ g_autofree char *origin_ref = NULL;
if (!ostree_parse_refspec (origin_refspec, &origin_remote, &origin_ref, error))
- goto out;
+ return FALSE;
+ g_autofree char *new_remote = NULL;
+ g_autofree char *new_ref = NULL;
/* Allow just switching remotes */
if (g_str_has_suffix (new_provided_refspec, ":"))
{
else
{
if (!ostree_parse_refspec (new_provided_refspec, &new_remote, &new_ref, error))
- goto out;
+ return FALSE;
}
- if (!new_remote)
- remote = origin_remote;
- else
- remote = new_remote;
-
+ const char* remote = new_remote ?: origin_remote;
+ g_autofree char *new_refspec = NULL;
if (remote)
new_refspec = g_strconcat (remote, ":", new_ref, NULL);
else
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Old and new refs are equal: %s", new_refspec);
- goto out;
+ return FALSE;
}
- new_origin = ostree_sysroot_origin_new_from_refspec (sysroot, new_refspec);
+ g_autoptr(GKeyFile) new_origin = ostree_sysroot_origin_new_from_refspec (sysroot, new_refspec);
if (!ostree_sysroot_upgrader_set_origin (upgrader, new_origin, cancellable, error))
- goto out;
+ return FALSE;
{ g_auto(GLnxConsoleRef) console = { 0, };
glnx_console_lock (&console);
+ g_autoptr(OstreeAsyncProgress) progress = NULL;
if (console.is_tty)
progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console);
/* Always allow older...there's not going to be a chronological
* relationship necessarily.
*/
+ gboolean changed;
if (!ostree_sysroot_upgrader_pull (upgrader, 0,
OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER,
progress, &changed,
cancellable, error))
- goto out;
+ return FALSE;
if (progress)
ostree_async_progress_finish (progress);
}
if (!ostree_sysroot_upgrader_deploy (upgrader, cancellable, error))
- goto out;
-
- if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
- goto out;
+ return FALSE;
+ OstreeRepo *repo = ostree_sysroot_repo (sysroot);
if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
- goto out;
+ return FALSE;
g_print ("Deleting ref '%s:%s'\n", origin_remote, origin_ref);
ostree_repo_transaction_set_ref (repo, origin_remote, origin_ref, NULL);
-
+
if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error))
- goto out;
-
+ return FALSE;
+
if (opt_reboot)
{
if (!ot_admin_execve_reboot (sysroot, error))
- goto out;
+ return FALSE;
}
- ret = TRUE;
- out:
- return ret;
+ return TRUE;
}
gboolean
ot_admin_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GError **error)
{
- gboolean ret = FALSE;
- g_autoptr(GOptionContext) context = NULL;
- g_autoptr(OstreeSysroot) sysroot = NULL;
- g_autoptr(OstreeSysrootUpgrader) upgrader = NULL;
- g_autoptr(GKeyFile) origin = NULL;
- g_autoptr(OstreeAsyncProgress) progress = NULL;
- gboolean changed;
- OstreeSysrootUpgraderPullFlags upgraderpullflags = 0;
-
- context = g_option_context_new ("Construct new tree from current origin and deploy it, if it changed");
+ g_autoptr(GOptionContext) context = g_option_context_new ("Construct new tree from current origin and deploy it, if it changed");
+ g_autoptr(OstreeSysroot) sysroot = NULL;
if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
&sysroot, cancellable, error))
- goto out;
+ return FALSE;
if (opt_pull_only && opt_deploy_only)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Cannot simultaneously specify --pull-only and --deploy-only");
- goto out;
+ return FALSE;
}
else if (opt_pull_only && opt_reboot)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Cannot simultaneously specify --pull-only and --reboot");
- goto out;
+ return FALSE;
}
if (!ostree_sysroot_load (sysroot, cancellable, error))
- goto out;
+ return FALSE;
- upgrader = ostree_sysroot_upgrader_new_for_os (sysroot, opt_osname,
- cancellable, error);
+ g_autoptr(OstreeSysrootUpgrader) upgrader =
+ ostree_sysroot_upgrader_new_for_os (sysroot, opt_osname,
+ cancellable, error);
if (!upgrader)
- goto out;
+ return FALSE;
- origin = ostree_sysroot_upgrader_dup_origin (upgrader);
+ g_autoptr(GKeyFile) origin = ostree_sysroot_upgrader_dup_origin (upgrader);
if (origin != NULL)
{
gboolean origin_changed = FALSE;
{
/* XXX GCancellable parameter is not used. */
if (!ostree_sysroot_upgrader_set_origin (upgrader, origin, NULL, error))
- goto out;
+ return FALSE;
}
}
+ gboolean changed;
+ OstreeSysrootUpgraderPullFlags upgraderpullflags = 0;
if (opt_deploy_only)
upgraderpullflags |= OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_SYNTHETIC;
{ g_auto(GLnxConsoleRef) console = { 0, };
glnx_console_lock (&console);
+ g_autoptr(OstreeAsyncProgress) progress = NULL;
if (console.is_tty)
progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console);
*/
if (opt_pull_only)
(void) ostree_sysroot_cleanup (sysroot, NULL, NULL);
- goto out;
+ return FALSE;
}
if (progress)
if (!opt_pull_only)
{
if (!ostree_sysroot_upgrader_deploy (upgrader, cancellable, error))
- goto out;
+ return FALSE;
}
if (opt_reboot)
{
if (!ot_admin_execve_reboot (sysroot, error))
- goto out;
+ return FALSE;
}
}
- ret = TRUE;
- out:
- return ret;
+ return TRUE;
}