bin/admin: Do sysroot loading during argument parsing
authorColin Walters <walters@verbum.org>
Fri, 1 Sep 2017 19:01:18 +0000 (15:01 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 1 Sep 2017 21:34:33 +0000 (21:34 +0000)
Followup from previous patch - we can now centralize the sysroot loading.
Besides the obvious cleanup value, this is also prep for dropping an
`ostree_sysroot_get_path()` user.

Closes: #1123
Approved by: jlebon

13 files changed:
src/ostree/ot-admin-builtin-cleanup.c
src/ostree/ot-admin-builtin-deploy.c
src/ostree/ot-admin-builtin-diff.c
src/ostree/ot-admin-builtin-set-origin.c
src/ostree/ot-admin-builtin-status.c
src/ostree/ot-admin-builtin-switch.c
src/ostree/ot-admin-builtin-undeploy.c
src/ostree/ot-admin-builtin-unlock.c
src/ostree/ot-admin-builtin-upgrade.c
src/ostree/ot-admin-instutil-builtin-grub2-generate.c
src/ostree/ot-admin-instutil-builtin-selinux-ensure-labeled.c
src/ostree/ot-admin-instutil-builtin-set-kargs.c
src/ostree/ot-main.c

index 13caa7f46e2f9130390bb867d082a8cde74807fa..a3b0a880fb03c7556c68a1ba4c0bef98e156c604 100644 (file)
@@ -52,9 +52,6 @@ ot_admin_builtin_cleanup (int argc, char **argv, GCancellable *cancellable, GErr
                                           &sysroot, cancellable, error))
     goto out;
 
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    goto out;
-
   if (!ostree_sysroot_cleanup (sysroot, cancellable, error))
     goto out;
 
index fa588f876a5060a02aee1c308ed0dd7ab649321d..e46ad02576f2a8da76d02449fba7211b6b66cbba 100644 (file)
@@ -82,8 +82,6 @@ ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GErro
 
   const char *refspec = argv[1];
 
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    return FALSE;
   OstreeRepo *repo = ostree_sysroot_repo (sysroot);
 
   /* Find the currently booted deployment, if any; we will ensure it
index 0419f2e14755a215283c297e277aa7e960dfe476..9967286687a420b05e88522d1706a89bd3c79dd8 100644 (file)
@@ -63,9 +63,6 @@ ot_admin_builtin_diff (int argc, char **argv, GCancellable *cancellable, GError
                                           OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
                                           &sysroot, cancellable, error))
     goto out;
-  
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    goto out;
 
   if (!ot_admin_require_booted_deployment_or_osname (sysroot, opt_osname,
                                                      cancellable, error))
index c49f575a7453f8453b0a2c9fd34ab3eab2e94f36..e6020cbecfead9791896f7f1fddd1d90c4af9f56 100644 (file)
@@ -75,9 +75,6 @@ ot_admin_builtin_set_origin (int argc, char **argv, GCancellable *cancellable, G
   if (argc > 3)
     branch = argv[3];
 
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    goto out;
-
   if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
     goto out;
 
index 3dd7aec5c44d6f80f9209557cad4f48c28f0c47f..561079744d6e32b0fcd8dbc3d307869652a8a38f 100644 (file)
@@ -108,9 +108,6 @@ ot_admin_builtin_status (int argc, char **argv, GCancellable *cancellable, GErro
                                           &sysroot, cancellable, error))
     goto out;
 
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    goto out;
-
   if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
     goto out;
 
index 3b54ea85072b775a1b482328bd3fe8ad6ae52f22..48fb27264bf815a83adcdb716968d2d8be3bb3b9 100644 (file)
@@ -63,9 +63,6 @@ ot_admin_builtin_switch (int argc, char **argv, GCancellable *cancellable, GErro
 
   const char *new_provided_refspec = argv[1];
 
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    return FALSE;
-
   g_autoptr(OstreeSysrootUpgrader) upgrader =
     ostree_sysroot_upgrader_new_for_os_with_flags (sysroot, opt_osname,
                                                    OSTREE_SYSROOT_UPGRADER_FLAGS_IGNORE_UNCONFIGURED,
index c0ff89ef13f06d089a796a6f2237023cd3bea25b..d16c927e5eb4a1f4ccaf0a5b438237cab03a040b 100644 (file)
@@ -60,8 +60,6 @@ ot_admin_builtin_undeploy (int argc, char **argv, GCancellable *cancellable, GEr
       return FALSE;
     }
 
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    return FALSE;
   current_deployments = ostree_sysroot_get_deployments (sysroot);
 
   deploy_index_str = argv[1];
index 053974149e108ae86afa8dd8a91b253c3ec46f79..36d99edb090d0d12d57691346938c6a5f2e74314 100644 (file)
@@ -65,9 +65,6 @@ ot_admin_builtin_unlock (int argc, char **argv, GCancellable *cancellable, GErro
       goto out;
     }
 
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    goto out;
-
   booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);
   if (!booted_deployment)
     {
index 77be95d259d086954554a1829fe3e449c773dd6b..8944904b7d9ff7e738d4f1c66f562d41e21072b6 100644 (file)
@@ -78,9 +78,6 @@ ot_admin_builtin_upgrade (int argc, char **argv, GCancellable *cancellable, GErr
       return FALSE;
     }
 
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    return FALSE;
-
   g_autoptr(OstreeSysrootUpgrader) upgrader =
     ostree_sysroot_upgrader_new_for_os (sysroot, opt_osname,
                                         cancellable, error);
index 07bd1eaa2077258ee1e822632a592c0cbdd1f8df..8ff0dc471b9fe6af2892da86a7bae70484e777c9 100644 (file)
@@ -53,9 +53,6 @@ ot_admin_instutil_builtin_grub2_generate (int argc, char **argv, GCancellable *c
                                           &sysroot, cancellable, error))
     goto out;
 
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    goto out;
-
   if (argc >= 2)
     {
       bootversion = (guint) g_ascii_strtoull (argv[1], NULL, 10);
index c754b18ac54773b917fc4d2db3024dc6f9ee630f..cbca7db37706db2dc642c06835bca41ce1d5c062 100644 (file)
@@ -204,9 +204,6 @@ ot_admin_instutil_builtin_selinux_ensure_labeled (int argc, char **argv, GCancel
                                           &sysroot, cancellable, error))
     goto out;
 
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    goto out;
-
   deployments = ostree_sysroot_get_deployments (sysroot);
   if (deployments->len == 0)
     {
index 1a37022c0a665b8bbbf99a164a71b9968d644cf2..7a98feb7fd49d2365c262e7de5ef6f3be5d1b3c7 100644 (file)
@@ -66,9 +66,6 @@ ot_admin_instutil_builtin_set_kargs (int argc, char **argv, GCancellable *cancel
                                           &sysroot, cancellable, error))
     goto out;
 
-  if (!ostree_sysroot_load (sysroot, cancellable, error))
-    goto out;
-
   deployments = ostree_sysroot_get_deployments (sysroot);
   if (deployments->len == 0)
     {
index 48281c26c7703ee2e687dd15fec12d6e8e5bbda9..cd7f0f4c5ae32ef8c6a017e5f4acaab1ca58d9e3 100644 (file)
@@ -391,6 +391,16 @@ ostree_admin_option_context_parse (GOptionContext *context,
   g_autoptr(OstreeSysroot) sysroot = ostree_sysroot_new (sysroot_path);
   g_signal_connect (sysroot, "journal-msg", G_CALLBACK (on_sysroot_journal_msg), NULL);
 
+  if ((flags & OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED) == 0)
+    {
+      /* Released when sysroot is finalized, or on process exit */
+      if (!ot_admin_sysroot_lock (sysroot, error))
+        return FALSE;
+    }
+
+  if (!ostree_sysroot_load (sysroot, cancellable, error))
+    return FALSE;
+
   if (flags & OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER)
     {
       GFile *path = ostree_sysroot_get_path (sysroot);
@@ -411,9 +421,6 @@ ostree_admin_option_context_parse (GOptionContext *context,
       g_autoptr(GFile) deployment_file = NULL;
       g_autofree char *deployment_path = NULL;
 
-      if (!ostree_sysroot_load (sysroot, cancellable, error))
-        return FALSE;
-
       deployments = ostree_sysroot_get_deployments (sysroot);
       if (deployments->len == 0)
         return glnx_throw (error, "Unable to find a deployment in sysroot");
@@ -433,13 +440,6 @@ ostree_admin_option_context_parse (GOptionContext *context,
       exit (EXIT_SUCCESS);
     }
 
-  if ((flags & OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED) == 0)
-    {
-      /* Released when sysroot is finalized, or on process exit */
-      if (!ot_admin_sysroot_lock (sysroot, error))
-        return FALSE;
-    }
-
   if (out_sysroot)
     *out_sysroot = g_steal_pointer (&sysroot);