upgrader: Allow overriding the commit to pull

Upgrader now looks for an "override-commit" key in the origin file
with a commit checksum, which causes the upgrader to pull and deploy
the specified commit rather than the latest available commit on the
origin refspec.
This commit is contained in:
Matthew Barnes 2015-10-01 19:02:11 -04:00
parent 41ab26356c
commit 39b732ffaa
1 changed files with 34 additions and 5 deletions

View File

@ -47,6 +47,7 @@ struct OstreeSysrootUpgrader {
GKeyFile *origin; GKeyFile *origin;
char *origin_remote; char *origin_remote;
char *origin_ref; char *origin_ref;
char *override_csum;
char *new_revision; char *new_revision;
}; };
@ -72,6 +73,7 @@ parse_refspec (OstreeSysrootUpgrader *self,
gboolean ret = FALSE; gboolean ret = FALSE;
g_autofree char *origin_refspec = NULL; g_autofree char *origin_refspec = NULL;
g_autofree char *unconfigured_state = NULL; g_autofree char *unconfigured_state = NULL;
g_autofree char *csum = NULL;
if ((self->flags & OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED) == 0) if ((self->flags & OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED) == 0)
{ {
@ -99,7 +101,12 @@ parse_refspec (OstreeSysrootUpgrader *self,
&self->origin_ref, &self->origin_ref,
error)) error))
goto out; goto out;
csum = g_key_file_get_string (self->origin, "origin", "override-commit", NULL);
if (csum != NULL && !ostree_validate_checksum_string (csum, error))
goto out;
self->override_csum = g_steal_pointer (&csum);
ret = TRUE; ret = TRUE;
out: out:
return ret; return ret;
@ -180,6 +187,7 @@ ostree_sysroot_upgrader_finalize (GObject *object)
g_key_file_unref (self->origin); g_key_file_unref (self->origin);
g_free (self->origin_remote); g_free (self->origin_remote);
g_free (self->origin_ref); g_free (self->origin_ref);
g_free (self->override_csum);
G_OBJECT_CLASS (ostree_sysroot_upgrader_parent_class)->finalize (object); G_OBJECT_CLASS (ostree_sysroot_upgrader_parent_class)->finalize (object);
} }
@ -520,11 +528,16 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self,
{ {
gboolean ret = FALSE; gboolean ret = FALSE;
glnx_unref_object OstreeRepo *repo = NULL; glnx_unref_object OstreeRepo *repo = NULL;
char *refs_to_fetch[] = { self->origin_ref, NULL }; char *refs_to_fetch[] = { NULL, NULL };
const char *from_revision = NULL; const char *from_revision = NULL;
g_autofree char *new_revision = NULL; g_autofree char *new_revision = NULL;
g_autofree char *origin_refspec = NULL; g_autofree char *origin_refspec = NULL;
if (self->override_csum != NULL)
refs_to_fetch[0] = self->override_csum;
else
refs_to_fetch[0] = self->origin_ref;
if (!ostree_sysroot_get_repo (self->sysroot, &repo, cancellable, error)) if (!ostree_sysroot_get_repo (self->sysroot, &repo, cancellable, error))
goto out; goto out;
@ -547,9 +560,25 @@ ostree_sysroot_upgrader_pull_one_dir (OstreeSysrootUpgrader *self,
ostree_async_progress_finish (progress); ostree_async_progress_finish (progress);
} }
if (!ostree_repo_resolve_rev (repo, origin_refspec, FALSE, &self->new_revision, if (self->override_csum != NULL)
error)) {
goto out; if (!ostree_repo_set_ref_immediate (repo,
self->origin_remote,
self->origin_ref,
self->override_csum,
cancellable,
error))
goto out;
self->new_revision = g_strdup (self->override_csum);
}
else
{
if (!ostree_repo_resolve_rev (repo, origin_refspec, FALSE,
&self->new_revision, error))
goto out;
}
if (g_strcmp0 (from_revision, self->new_revision) == 0) if (g_strcmp0 (from_revision, self->new_revision) == 0)
{ {