mirror of
https://github.com/ostreedev/ostree.git
synced 2025-01-07 21:18:55 +03:00
admin: (cleanup) Add internal API to find a deployment given an index
At some point, we might want to expose a uniform way to refer to deployments by an index. At the moment undeploy is the only command that does. I plan to introduce another command which optionally takes an index, so prepare a helper function for this.
This commit is contained in:
parent
ce957f8649
commit
0eac91a253
@ -62,20 +62,10 @@ ot_admin_builtin_undeploy (int argc, char **argv, GCancellable *cancellable, GEr
|
||||
deploy_index_str = argv[1];
|
||||
deploy_index = atoi (deploy_index_str);
|
||||
|
||||
if (deploy_index < 0)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
"Invalid index %d", deploy_index);
|
||||
goto out;
|
||||
}
|
||||
if (deploy_index >= current_deployments->len)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
"Out of range index %d, expected < %d", deploy_index, current_deployments->len);
|
||||
goto out;
|
||||
}
|
||||
|
||||
target_deployment = g_object_ref (current_deployments->pdata[deploy_index]);
|
||||
target_deployment = ot_admin_get_indexed_deployment (sysroot, deploy_index, error);
|
||||
if (!target_deployment)
|
||||
goto out;
|
||||
|
||||
if (target_deployment == ostree_sysroot_get_booted_deployment (sysroot))
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
|
@ -71,3 +71,30 @@ ot_admin_checksum_version (GVariant *checksum)
|
||||
|
||||
return g_strdup (ret);
|
||||
}
|
||||
|
||||
OstreeDeployment *
|
||||
ot_admin_get_indexed_deployment (OstreeSysroot *sysroot,
|
||||
int index,
|
||||
GError **error)
|
||||
|
||||
{
|
||||
gs_unref_ptrarray GPtrArray *current_deployments =
|
||||
ostree_sysroot_get_deployments (sysroot);
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
"Invalid index %d", index);
|
||||
return NULL;
|
||||
}
|
||||
if (index >= current_deployments->len)
|
||||
{
|
||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
"Out of range deployment index %d, expected < %d", index,
|
||||
current_deployments->len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_object_ref (current_deployments->pdata[index]);
|
||||
}
|
||||
|
||||
|
@ -36,5 +36,11 @@ ot_admin_require_booted_deployment_or_osname (OstreeSysroot *sysroot,
|
||||
char *
|
||||
ot_admin_checksum_version (GVariant *checksum);
|
||||
|
||||
OstreeDeployment *
|
||||
ot_admin_get_indexed_deployment (OstreeSysroot *sysroot,
|
||||
int index,
|
||||
GError **error);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user