Skip to content

Commit

Permalink
upgrade: Add support for --pull-only and --deploy-only
Browse files Browse the repository at this point in the history
This makes it easier to script downloading updates in the background,
and only do deployments just before rebooting.

Partially addresses ostreedev#640
  • Loading branch information
cgwalters committed Jan 5, 2017
1 parent d9f43cd commit 47cfd4a
Showing 1 changed file with 49 additions and 15 deletions.
64 changes: 49 additions & 15 deletions src/ostree/ot-admin-builtin-upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

static gboolean opt_reboot;
static gboolean opt_allow_downgrade;
static gboolean opt_pull_only;
static gboolean opt_deploy_only;
static char *opt_osname;
static char *opt_override_commit;

Expand All @@ -42,6 +44,8 @@ static GOptionEntry options[] = {
{ "reboot", 'r', 0, G_OPTION_ARG_NONE, &opt_reboot, "Reboot after a successful upgrade", NULL },
{ "allow-downgrade", 0, 0, G_OPTION_ARG_NONE, &opt_allow_downgrade, "Permit deployment of chronologically older trees", NULL },
{ "override-commit", 0, 0, G_OPTION_ARG_STRING, &opt_override_commit, "Deploy CHECKSUM instead of the latest tree", "CHECKSUM" },
{ "pull-only", 0, 0, G_OPTION_ARG_NONE, &opt_pull_only, "Do not create a deployment, just download", NULL },
{ "deploy-only", 0, 0, G_OPTION_ARG_NONE, &opt_deploy_only, "Do not pull, only deploy", NULL },
{ NULL }
};

Expand All @@ -64,6 +68,13 @@ ot_admin_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GErr
&sysroot, cancellable, error))
goto out;

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;
}

if (!ostree_sysroot_load (sysroot, cancellable, error))
goto out;

Expand Down Expand Up @@ -104,22 +115,42 @@ ot_admin_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GErr
}
}

{ g_auto(GLnxConsoleRef) console = { 0, };
glnx_console_lock (&console);
/* In the pull-only case, we do a cleanup here to ensure that if multiple
* commits were pulled, we garbage collect any intermediate data before
* pulling more. This is really a best practice in general, but for maximum
* compatiblity, we only do cleanup if a user specifies the new --pull-only
* option. Otherwise, we would break the case of trying to deploy a commit
* that isn't directly referenced.
*/
if (opt_pull_only)
{
if (!ostree_sysroot_cleanup (sysroot, cancellable, error))
goto out;
}

if (console.is_tty)
progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console);
if (opt_deploy_only)
{
/* FIXME - change this to compare the refspec with the origin */
changed = TRUE;
}
else
{
g_auto(GLnxConsoleRef) console = { 0, };
glnx_console_lock (&console);

if (opt_allow_downgrade)
upgraderpullflags |= OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER;

if (!ostree_sysroot_upgrader_pull (upgrader, 0, upgraderpullflags,
progress, &changed,
cancellable, error))
goto out;
if (console.is_tty)
progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console);

if (opt_allow_downgrade)
upgraderpullflags |= OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER;

if (!ostree_sysroot_upgrader_pull (upgrader, 0, upgraderpullflags,
progress, &changed,
cancellable, error))
goto out;

if (progress)
ostree_async_progress_finish (progress);
if (progress)
ostree_async_progress_finish (progress);
}

if (!changed)
Expand All @@ -128,8 +159,11 @@ ot_admin_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GErr
}
else
{
if (!ostree_sysroot_upgrader_deploy (upgrader, cancellable, error))
goto out;
if (!opt_pull_only)
{
if (!ostree_sysroot_upgrader_deploy (upgrader, cancellable, error))
goto out;
}

if (opt_reboot)
{
Expand Down

0 comments on commit 47cfd4a

Please sign in to comment.