[ostree] admin: (cleanup) Add internal API to find a deployment given an index



commit 0eac91a253d0c2451eb4c10ddd63bc172509939d
Author: Colin Walters <walters verbum org>
Date:   Fri Jan 16 12:57:39 2015 -0500

    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.

 src/ostree/ot-admin-builtin-undeploy.c |   18 ++++--------------
 src/ostree/ot-admin-functions.c        |   27 +++++++++++++++++++++++++++
 src/ostree/ot-admin-functions.h        |    6 ++++++
 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 edf89bf..9196e5b 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 ff62357..0c8c28f 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 ea147c8..21e4a7d 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
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]