summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2015-01-16 12:57:39 -0500
committerColin Walters <walters@verbum.org>2015-01-19 13:45:11 -0500
commit0eac91a253d0c2451eb4c10ddd63bc172509939d (patch)
tree324c44483825aa4776142ce8d945c3e48d65e3e2
parentce957f864907e665591e02455ed87f70d3ebe930 (diff)
downloadostree-0eac91a253d0c2451eb4c10ddd63bc172509939d.tar.gz
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.
-rw-r--r--src/ostree/ot-admin-builtin-undeploy.c18
-rw-r--r--src/ostree/ot-admin-functions.c27
-rw-r--r--src/ostree/ot-admin-functions.h6
3 files changed, 37 insertions, 14 deletions
diff --git a/src/ostree/ot-admin-builtin-undeploy.c b/src/ostree/ot-admin-builtin-undeploy.c
index edf89bf4..9196e5bf 100644
--- a/src/ostree/ot-admin-builtin-undeploy.c
+++ b/src/ostree/ot-admin-builtin-undeploy.c
@@ -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,
diff --git a/src/ostree/ot-admin-functions.c b/src/ostree/ot-admin-functions.c
index ff623574..0c8c28f2 100644
--- a/src/ostree/ot-admin-functions.c
+++ b/src/ostree/ot-admin-functions.c
@@ -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]);
+}
+
diff --git a/src/ostree/ot-admin-functions.h b/src/ostree/ot-admin-functions.h
index ea147c84..21e4a7d7 100644
--- a/src/ostree/ot-admin-functions.h
+++ b/src/ostree/ot-admin-functions.h
@@ -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