RpmOstreeOrigin: don't error on unconfigured state

This is a follow-up to 775c781 (#626). Really, RpmOstreeOrigin shouldn't
concern itself with whether the origin is unconfigured. Its main goal
should be to parse it out and make it easy for users to modify it. That
sort of business logic lives in the upgrader, which *should* be
concerned if the origin in unconfigured.

Closes: #634
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2017-02-16 12:46:13 -05:00 committed by Atomic Bot
parent 62c7242a98
commit b7613dcc81
5 changed files with 30 additions and 44 deletions

View File

@ -100,16 +100,22 @@ parse_origin_keyfile (RpmOstreeSysrootUpgrader *self,
GCancellable *cancellable,
GError **error)
{
RpmOstreeOriginParseFlags origin_flags = 0;
g_clear_pointer (&self->origin, (GDestroyNotify)rpmostree_origin_unref);
if (self->flags & RPMOSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED)
origin_flags |= RPMOSTREE_ORIGIN_PARSE_FLAGS_IGNORE_UNCONFIGURED;
self->origin = rpmostree_origin_parse_keyfile (origin, origin_flags, error);
self->origin = rpmostree_origin_parse_keyfile (origin, error);
if (!self->origin)
return FALSE;
if (rpmostree_origin_get_unconfigured_state (self->origin) &&
!(self->flags & RPMOSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED))
{
/* explicit action is required OS creator to upgrade, print their text as an error */
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"origin unconfigured-state: %s",
rpmostree_origin_get_unconfigured_state (self->origin));
return FALSE;
}
return TRUE;
}
@ -1219,8 +1225,7 @@ clean_pkgcache_orphans (OstreeSysroot *sysroot,
OstreeDeployment *deployment = deployments->pdata[i];
g_autoptr(RpmOstreeOrigin) origin = NULL;
origin = rpmostree_origin_parse_deployment_ex (deployment, RPMOSTREE_ORIGIN_PARSE_FLAGS_IGNORE_UNCONFIGURED,
error);
origin = rpmostree_origin_parse_deployment (deployment, error);
if (!origin)
return FALSE;

View File

@ -191,8 +191,7 @@ rpmostreed_deployment_generate_variant (OstreeDeployment *deployment,
id = rpmostreed_deployment_generate_id (deployment);
origin = rpmostree_origin_parse_deployment_ex (deployment, RPMOSTREE_ORIGIN_PARSE_FLAGS_IGNORE_UNCONFIGURED,
error);
origin = rpmostree_origin_parse_deployment (deployment, error);
if (!origin)
return NULL;
@ -282,8 +281,7 @@ rpmostreed_commit_generate_cached_details_variant (OstreeDeployment *deployment,
{
g_autoptr(RpmOstreeOrigin) origin = NULL;
origin = rpmostree_origin_parse_deployment_ex (deployment, RPMOSTREE_ORIGIN_PARSE_FLAGS_IGNORE_UNCONFIGURED,
error);
origin = rpmostree_origin_parse_deployment (deployment, error);
if (!origin)
return NULL;
origin_refspec = g_strdup (rpmostree_origin_get_refspec (origin));

View File

@ -1214,8 +1214,7 @@ rpmostreed_os_load_internals (RpmostreedOS *self, GError **error)
g_autoptr(RpmOstreeOrigin) origin = NULL;
/* Don't fail here for unknown origin types */
origin = rpmostree_origin_parse_deployment_ex (merge_deployment, RPMOSTREE_ORIGIN_PARSE_FLAGS_IGNORE_UNCONFIGURED,
NULL);
origin = rpmostree_origin_parse_deployment (merge_deployment, NULL);
if (origin)
{
cached_update = rpmostreed_commit_generate_cached_details_variant (merge_deployment,

View File

@ -30,6 +30,7 @@ struct RpmOstreeOrigin {
char *refspec;
char **packages;
char *override_commit;
char *unconfigured_state;
};
static GKeyFile *
@ -45,7 +46,6 @@ keyfile_dup (GKeyFile *kf)
RpmOstreeOrigin *
rpmostree_origin_parse_keyfile (GKeyFile *origin,
RpmOstreeOriginParseFlags flags,
GError **error)
{
g_autoptr(RpmOstreeOrigin) ret = NULL;
@ -57,19 +57,7 @@ rpmostree_origin_parse_keyfile (GKeyFile *origin,
/* NOTE hack here - see https://github.com/ostreedev/ostree/pull/343 */
g_key_file_remove_key (ret->kf, "origin", "unlocked", NULL);
if ((flags & RPMOSTREE_ORIGIN_PARSE_FLAGS_IGNORE_UNCONFIGURED) == 0)
{
g_autofree char *unconfigured_state = NULL;
/* If explicit action by the OS creator is requried to upgrade, print their text as an error */
unconfigured_state = g_key_file_get_string (origin, "origin", "unconfigured-state", NULL);
if (unconfigured_state)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"origin unconfigured-state: %s", unconfigured_state);
return NULL;
}
}
ret->unconfigured_state = g_key_file_get_string (ret->kf, "origin", "unconfigured-state", NULL);
ret->refspec = g_key_file_get_string (ret->kf, "origin", "refspec", NULL);
if (!ret->refspec)
@ -170,6 +158,7 @@ rpmostree_origin_unref (RpmOstreeOrigin *origin)
return;
g_key_file_unref (origin->kf);
g_free (origin->refspec);
g_free (origin->unconfigured_state);
g_strfreev (origin->packages);
g_free (origin);
}
@ -260,3 +249,9 @@ rpmostree_origin_set_rebase (RpmOstreeOrigin *origin,
return TRUE;
}
const char*
rpmostree_origin_get_unconfigured_state (RpmOstreeOrigin *origin)
{
return origin->unconfigured_state;
}

View File

@ -27,20 +27,14 @@ RpmOstreeOrigin *rpmostree_origin_ref (RpmOstreeOrigin *origin);
void rpmostree_origin_unref (RpmOstreeOrigin *origin);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(RpmOstreeOrigin, rpmostree_origin_unref)
typedef enum {
RPMOSTREE_ORIGIN_PARSE_FLAGS_IGNORE_UNCONFIGURED = (1 << 0)
} RpmOstreeOriginParseFlags;
RpmOstreeOrigin *
rpmostree_origin_parse_keyfile (GKeyFile *keyfile,
RpmOstreeOriginParseFlags flags,
GError **error);
static inline
RpmOstreeOrigin *
rpmostree_origin_parse_deployment_ex (OstreeDeployment *deployment,
RpmOstreeOriginParseFlags flags,
GError **error)
rpmostree_origin_parse_deployment (OstreeDeployment *deployment,
GError **error)
{
GKeyFile *origin = ostree_deployment_get_origin (deployment);
if (!origin)
@ -51,15 +45,7 @@ rpmostree_origin_parse_deployment_ex (OstreeDeployment *deployment,
ostree_deployment_get_deployserial (deployment));
return NULL;
}
return rpmostree_origin_parse_keyfile (origin, flags, error);
}
static inline
RpmOstreeOrigin *
rpmostree_origin_parse_deployment (OstreeDeployment *deployment,
GError **error)
{
return rpmostree_origin_parse_deployment_ex (deployment, 0, error);
return rpmostree_origin_parse_keyfile (origin, error);
}
RpmOstreeOrigin *
@ -105,3 +91,6 @@ gboolean
rpmostree_origin_set_rebase (RpmOstreeOrigin *origin,
const char *new_refspec,
GError **error);
const char *
rpmostree_origin_get_unconfigured_state (RpmOstreeOrigin *origin);