sysroot: Add API to clean up transient keys in origin files
The `origin/unlocked` and `origin/override-commit` keys are examples of state that's really transient; we don't want to maintain them across upgrades. Right now there are bits for this in both `ostree admin upgrade` as well as in rpm-ostree. This new API will slightly clean up both cases, but it's really prep for adding a concept of deployment "pinning" that will live in the new `libostree-transient` group. Closes: #1464 Approved by: jlebon
This commit is contained in:
parent
2f5a34bed9
commit
c40a47e965
|
|
@ -173,6 +173,7 @@ ostree_deployment_set_index
|
||||||
ostree_deployment_set_bootserial
|
ostree_deployment_set_bootserial
|
||||||
ostree_deployment_set_bootconfig
|
ostree_deployment_set_bootconfig
|
||||||
ostree_deployment_set_origin
|
ostree_deployment_set_origin
|
||||||
|
ostree_deployment_origin_remove_transient_state
|
||||||
ostree_deployment_clone
|
ostree_deployment_clone
|
||||||
ostree_deployment_unlocked_state_to_string
|
ostree_deployment_unlocked_state_to_string
|
||||||
<SUBSECTION Standard>
|
<SUBSECTION Standard>
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
/* Add new symbols here. Release commits should copy this section into -released.sym. */
|
/* Add new symbols here. Release commits should copy this section into -released.sym. */
|
||||||
LIBOSTREE_2018.3 {
|
LIBOSTREE_2018.3 {
|
||||||
|
ostree_deployment_origin_remove_transient_state;
|
||||||
} LIBOSTREE_2018.2;
|
} LIBOSTREE_2018.2;
|
||||||
|
|
||||||
/* Stub section for the stable release *after* this development one; don't
|
/* Stub section for the stable release *after* this development one; don't
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,35 @@ ostree_deployment_set_origin (OstreeDeployment *self, GKeyFile *origin)
|
||||||
self->origin = g_key_file_ref (origin);
|
self->origin = g_key_file_ref (origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ostree_deployment_origin_remove_transient_state:
|
||||||
|
* @origin: An origin
|
||||||
|
*
|
||||||
|
* The intention of an origin file is primarily describe the "inputs" that
|
||||||
|
* resulted in a deployment, and it's commonly used to derive the new state. For
|
||||||
|
* example, a key value (in pure libostree mode) is the "refspec". However,
|
||||||
|
* libostree (or other applications) may want to store "transient" state that
|
||||||
|
* should not be carried across upgrades.
|
||||||
|
*
|
||||||
|
* This function just removes all members of the `libostree-transient` group.
|
||||||
|
* The name of that group is available to all libostree users; best practice
|
||||||
|
* would be to prefix values underneath there with a short identifier for your
|
||||||
|
* software.
|
||||||
|
*
|
||||||
|
* Additionally, this function will remove the `origin/unlocked` and
|
||||||
|
* `origin/override-commit` members; these should be considered transient state
|
||||||
|
* that should have been under an explicit group.
|
||||||
|
*
|
||||||
|
* Since: 2018.3
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ostree_deployment_origin_remove_transient_state (GKeyFile *origin)
|
||||||
|
{
|
||||||
|
g_key_file_remove_group (origin, OSTREE_ORIGIN_TRANSIENT_GROUP, NULL);
|
||||||
|
g_key_file_remove_key (origin, "origin", "override-commit", NULL);
|
||||||
|
g_key_file_remove_key (origin, "origin", "unlocked", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_ostree_deployment_set_bootcsum (OstreeDeployment *self,
|
_ostree_deployment_set_bootcsum (OstreeDeployment *self,
|
||||||
const char *bootcsum)
|
const char *bootcsum)
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,17 @@ G_BEGIN_DECLS
|
||||||
#define OSTREE_DEPLOYMENT(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_DEPLOYMENT, OstreeDeployment))
|
#define OSTREE_DEPLOYMENT(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), OSTREE_TYPE_DEPLOYMENT, OstreeDeployment))
|
||||||
#define OSTREE_IS_DEPLOYMENT(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_DEPLOYMENT))
|
#define OSTREE_IS_DEPLOYMENT(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), OSTREE_TYPE_DEPLOYMENT))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OSTREE_ORIGIN_TRANSIENT_GROUP:
|
||||||
|
*
|
||||||
|
* The name of a `GKeyFile` group for data that should not
|
||||||
|
* be carried across upgrades. For more information,
|
||||||
|
* see ostree_deployment_origin_remove_transient_state().
|
||||||
|
*
|
||||||
|
* Since: 2018.3
|
||||||
|
*/
|
||||||
|
#define OSTREE_ORIGIN_TRANSIENT_GROUP "libostree-transient"
|
||||||
|
|
||||||
typedef struct _OstreeDeployment OstreeDeployment;
|
typedef struct _OstreeDeployment OstreeDeployment;
|
||||||
|
|
||||||
_OSTREE_PUBLIC
|
_OSTREE_PUBLIC
|
||||||
|
|
@ -62,6 +73,7 @@ OstreeBootconfigParser *ostree_deployment_get_bootconfig (OstreeDeployment *self
|
||||||
_OSTREE_PUBLIC
|
_OSTREE_PUBLIC
|
||||||
GKeyFile *ostree_deployment_get_origin (OstreeDeployment *self);
|
GKeyFile *ostree_deployment_get_origin (OstreeDeployment *self);
|
||||||
|
|
||||||
|
|
||||||
_OSTREE_PUBLIC
|
_OSTREE_PUBLIC
|
||||||
void ostree_deployment_set_index (OstreeDeployment *self, int index);
|
void ostree_deployment_set_index (OstreeDeployment *self, int index);
|
||||||
_OSTREE_PUBLIC
|
_OSTREE_PUBLIC
|
||||||
|
|
@ -71,6 +83,9 @@ void ostree_deployment_set_bootconfig (OstreeDeployment *self, OstreeBootconfigP
|
||||||
_OSTREE_PUBLIC
|
_OSTREE_PUBLIC
|
||||||
void ostree_deployment_set_origin (OstreeDeployment *self, GKeyFile *origin);
|
void ostree_deployment_set_origin (OstreeDeployment *self, GKeyFile *origin);
|
||||||
|
|
||||||
|
_OSTREE_PUBLIC
|
||||||
|
void ostree_deployment_origin_remove_transient_state (GKeyFile *origin);
|
||||||
|
|
||||||
_OSTREE_PUBLIC
|
_OSTREE_PUBLIC
|
||||||
OstreeDeployment *ostree_deployment_clone (OstreeDeployment *self);
|
OstreeDeployment *ostree_deployment_clone (OstreeDeployment *self);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,34 +88,19 @@ ot_admin_builtin_upgrade (int argc, char **argv, OstreeCommandInvocation *invoca
|
||||||
g_autoptr(GKeyFile) origin = ostree_sysroot_upgrader_dup_origin (upgrader);
|
g_autoptr(GKeyFile) origin = ostree_sysroot_upgrader_dup_origin (upgrader);
|
||||||
if (origin != NULL)
|
if (origin != NULL)
|
||||||
{
|
{
|
||||||
gboolean origin_changed = FALSE;
|
/* Should we consider requiring --discard-hotfix here? */
|
||||||
|
ostree_deployment_origin_remove_transient_state (origin);
|
||||||
if (opt_override_commit != NULL)
|
if (opt_override_commit != NULL)
|
||||||
{
|
{
|
||||||
/* Override the commit to pull and deploy. */
|
/* Override the commit to pull and deploy. */
|
||||||
g_key_file_set_string (origin, "origin",
|
g_key_file_set_string (origin, "origin",
|
||||||
"override-commit",
|
"override-commit",
|
||||||
opt_override_commit);
|
opt_override_commit);
|
||||||
origin_changed = TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Strip any override-commit from the origin file so
|
|
||||||
* we always upgrade to the latest available commit. */
|
|
||||||
origin_changed = g_key_file_remove_key (origin, "origin",
|
|
||||||
"override-commit", NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Should we consider requiring --discard-hotfix here? */
|
|
||||||
origin_changed |= g_key_file_remove_key (origin, "origin", "unlocked", NULL);
|
|
||||||
|
|
||||||
if (origin_changed)
|
|
||||||
{
|
|
||||||
/* XXX GCancellable parameter is not used. */
|
|
||||||
if (!ostree_sysroot_upgrader_set_origin (upgrader, origin, NULL, error))
|
if (!ostree_sysroot_upgrader_set_origin (upgrader, origin, NULL, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
gboolean changed;
|
gboolean changed;
|
||||||
OstreeSysrootUpgraderPullFlags upgraderpullflags = 0;
|
OstreeSysrootUpgraderPullFlags upgraderpullflags = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue