sysroot: Add _require_booted_deployment() API
This is a common pattern that is replicated both in our code and in rpm-ostree a lot. Let's add a canonical API.
This commit is contained in:
1 parent
d522f261db
commit
1b28e6041c
8 files changed
+33
-15
No files matched your search
@@ -25,6 +25,7 @@
|
||||
LIBOSTREE_2021.1 {
|
||||
global:
|
||||
ostree_commit_metadata_for_bootable;
|
||||
ostree_sysroot_require_booted_deployment;
|
||||
} LIBOSTREE_2020.8;
|
||||
|
||||
/* Stub section for the stable release *after* this development one; don't
|
||||
|
||||
@@ -3066,9 +3066,9 @@ ostree_sysroot_stage_tree_with_options (OstreeSysroot *self,
|
||||
if (!_ostree_sysroot_ensure_writable (self, error))
|
||||
return FALSE;
|
||||
|
||||
OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (self);
|
||||
OstreeDeployment *booted_deployment = ostree_sysroot_require_booted_deployment (self, error);
|
||||
if (booted_deployment == NULL)
|
||||
return glnx_throw (error, "Cannot stage a deployment when not currently booted into an OSTree system");
|
||||
return glnx_prefix_error (error, "Cannot stage deployment");
|
||||
|
||||
/* This is used by the testsuite to exercise the path unit, until it becomes the default
|
||||
* (which is pending on the preset making it everywhere). */
|
||||
|
||||
@@ -1246,6 +1246,27 @@ ostree_sysroot_get_booted_deployment (OstreeSysroot *self)
|
||||
return self->booted_deployment;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ostree_sysroot_require_booted_deployment:
|
||||
* @self: Sysroot
|
||||
*
|
||||
* Find the booted deployment, or return an error if not booted via OSTree.
|
||||
*
|
||||
* Returns: (transfer none) (not nullable): The currently booted deployment, or an error
|
||||
* Since: 2021.1
|
||||
*/
|
||||
OstreeDeployment *
|
||||
ostree_sysroot_require_booted_deployment (OstreeSysroot *self, GError **error)
|
||||
{
|
||||
g_return_val_if_fail (self->loadstate == OSTREE_SYSROOT_LOAD_STATE_LOADED, NULL);
|
||||
|
||||
if (!self->booted_deployment)
|
||||
return glnx_null_throw (error, "Not currently booted into an OSTree system");
|
||||
return self->booted_deployment;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ostree_sysroot_get_staged_deployment:
|
||||
* @self: Sysroot
|
||||
|
||||
@@ -85,6 +85,9 @@ GPtrArray *ostree_sysroot_get_deployments (OstreeSysroot *self);
|
||||
_OSTREE_PUBLIC
|
||||
OstreeDeployment *ostree_sysroot_get_booted_deployment (OstreeSysroot *self);
|
||||
_OSTREE_PUBLIC
|
||||
OstreeDeployment *
|
||||
ostree_sysroot_require_booted_deployment (OstreeSysroot *self, GError **error);
|
||||
_OSTREE_PUBLIC
|
||||
OstreeDeployment *ostree_sysroot_get_staged_deployment (OstreeSysroot *self);
|
||||
|
||||
_OSTREE_PUBLIC
|
||||
|
||||
Reference in new issue
Block a user