diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c index e6471ab5..65cfb7c3 100644 --- a/src/libostree/ostree-sysroot.c +++ b/src/libostree/ostree-sysroot.c @@ -256,7 +256,7 @@ ensure_sysroot_fd (OstreeSysroot *self, * Access a file descriptor that refers to the root directory of this * sysroot. ostree_sysroot_load() must have been invoked prior to * calling this function. - * + * * Returns: A file descriptor valid for the lifetime of @self */ int @@ -276,7 +276,7 @@ _ostree_sysroot_bump_mtime (OstreeSysroot *self, glnx_set_prefix_error_from_errno (error, "%s", "futimens"); return FALSE; } - return TRUE; + return TRUE; } /** @@ -894,7 +894,7 @@ ostree_sysroot_get_subbootversion (OstreeSysroot *self) /** * ostree_sysroot_get_booted_deployment: * @self: Sysroot - * + * * Returns: (transfer none): The currently booted deployment, or %NULL if none */ OstreeDeployment * @@ -1377,7 +1377,7 @@ lock_in_thread (GTask *task, * @cancellable: Cancellable * @callback: Callback * @user_data: User data - * + * * An asynchronous version of ostree_sysroot_lock(). */ void @@ -1395,7 +1395,7 @@ ostree_sysroot_lock_async (OstreeSysroot *self, * @self: Self * @result: Result * @error: Error - * + * * Call when ostree_sysroot_lock_async() is ready. */ gboolean @@ -1413,7 +1413,7 @@ ostree_sysroot_lock_finish (OstreeSysroot *self, * @osname: Name group of operating system checkouts * @cancellable: Cancellable * @error: Error - * + * * Initialize the directory structure for an "osname", which is a * group of operating system deployments, with a shared `/var`. One * is required for generating a deployment. @@ -1505,36 +1505,34 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, GCancellable *cancellable, GError **error) { - gboolean ret = FALSE; - guint i; - OstreeDeployment *booted_deployment = NULL; - g_autoptr(GPtrArray) deployments = NULL; - g_autoptr(GPtrArray) new_deployments = g_ptr_array_new_with_free_func (g_object_unref); - const gboolean postclean = (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN) == 0; - OstreeSysrootWriteDeploymentsOpts write_opts = { .do_postclean = postclean }; - gboolean retain = (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN) > 0; - const gboolean make_default = !((flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT) > 0); - gboolean added_new = FALSE; + const gboolean postclean = + (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN) == 0; + const gboolean retain = + (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN) > 0; + const gboolean make_default = + !((flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT) > 0); - deployments = ostree_sysroot_get_deployments (sysroot); - booted_deployment = ostree_sysroot_get_booted_deployment (sysroot); + g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot); + OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot); if (osname == NULL && booted_deployment) osname = ostree_deployment_get_osname (booted_deployment); + gboolean added_new = FALSE; + g_autoptr(GPtrArray) new_deployments = g_ptr_array_new_with_free_func (g_object_unref); if (make_default) { g_ptr_array_add (new_deployments, g_object_ref (new_deployment)); added_new = TRUE; } - for (i = 0; i < deployments->len; i++) + for (guint i = 0; i < deployments->len; i++) { OstreeDeployment *deployment = deployments->pdata[i]; - const gboolean is_merge_or_booted = + const gboolean is_merge_or_booted = ostree_deployment_equal (deployment, booted_deployment) || ostree_deployment_equal (deployment, merge_deployment); - + /* Keep deployments with different osnames, as well as the * booted and merge deployments */ @@ -1562,13 +1560,12 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot, added_new = TRUE; } + OstreeSysrootWriteDeploymentsOpts write_opts = { .do_postclean = postclean }; if (!ostree_sysroot_write_deployments_with_options (sysroot, new_deployments, &write_opts, cancellable, error)) - goto out; + return FALSE; - ret = TRUE; - out: - return ret; + return TRUE; } /* Deploy a copy of @target_deployment */ diff --git a/src/ostree/ot-admin-builtin-deploy.c b/src/ostree/ot-admin-builtin-deploy.c index 5df4923c..d67de791 100644 --- a/src/ostree/ot-admin-builtin-deploy.c +++ b/src/ostree/ot-admin-builtin-deploy.c @@ -57,64 +57,55 @@ static GOptionEntry options[] = { gboolean ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GError **error) { - gboolean ret = FALSE; - const char *refspec; - g_autoptr(GOptionContext) context = NULL; - g_autoptr(OstreeSysroot) sysroot = NULL; - g_autoptr(GKeyFile) origin = NULL; - g_autoptr(OstreeRepo) repo = NULL; - g_autoptr(OstreeDeployment) new_deployment = NULL; - g_autoptr(OstreeDeployment) merge_deployment = NULL; - g_autofree char *revision = NULL; __attribute__((cleanup(_ostree_kernel_args_cleanup))) OstreeKernelArgs *kargs = NULL; - context = g_option_context_new ("REFSPEC - Checkout revision REFSPEC as the new default deployment"); + g_autoptr(GOptionContext) context = + g_option_context_new ("REFSPEC - Checkout revision REFSPEC as the new default deployment"); + g_autoptr(OstreeSysroot) sysroot = NULL; if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, &sysroot, cancellable, error)) - goto out; + return FALSE; if (argc < 2) { ot_util_usage_error (context, "REF/REV must be specified", error); - goto out; + return FALSE; } - refspec = argv[1]; + const char *refspec = argv[1]; if (!ostree_sysroot_load (sysroot, cancellable, error)) - goto out; - - if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error)) - goto out; + return FALSE; + OstreeRepo *repo = ostree_sysroot_repo (sysroot); /* Find the currently booted deployment, if any; we will ensure it * is present in the new deployment list. */ if (!ot_admin_require_booted_deployment_or_osname (sysroot, opt_osname, cancellable, error)) - { - g_prefix_error (error, "Looking for booted deployment: "); - goto out; - } + return glnx_prefix_error (error, "Looking for booted deployment"); + g_autoptr(GKeyFile) origin = NULL; if (opt_origin_path) { origin = g_key_file_new (); - + if (!g_key_file_load_from_file (origin, opt_origin_path, 0, error)) - goto out; + return FALSE; } else { origin = ostree_sysroot_origin_new_from_refspec (sysroot, refspec); } + g_autofree char *revision = NULL; if (!ostree_repo_resolve_rev (repo, refspec, FALSE, &revision, error)) - goto out; + return FALSE; - merge_deployment = ostree_sysroot_get_merge_deployment (sysroot, opt_osname); + g_autoptr(OstreeDeployment) merge_deployment = + ostree_sysroot_get_merge_deployment (sysroot, opt_osname); /* Here we perform cleanup of any leftover data from previous * partial failures. This avoids having to call @@ -124,10 +115,7 @@ ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GErro * we find it. */ if (!ostree_sysroot_prepare_cleanup (sysroot, cancellable, error)) - { - g_prefix_error (error, "Performing initial cleanup: "); - goto out; - } + return glnx_prefix_error (error, "Performing initial cleanup"); kargs = _ostree_kernel_args_new (); @@ -137,7 +125,7 @@ ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GErro if (opt_kernel_proc_cmdline) { if (!_ostree_kernel_args_append_proc_cmdline (kargs, cancellable, error)) - goto out; + return FALSE; } else if (merge_deployment) { @@ -160,21 +148,20 @@ ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GErro { g_auto(GStrv) kargs_strv = _ostree_kernel_args_to_strv (kargs); + g_autoptr(OstreeDeployment) new_deployment = NULL; if (!ostree_sysroot_deploy_tree (sysroot, opt_osname, revision, origin, merge_deployment, kargs_strv, &new_deployment, cancellable, error)) - goto out; + return FALSE; } if (!ostree_sysroot_simple_write_deployment (sysroot, opt_osname, new_deployment, merge_deployment, opt_retain ? OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN : 0, cancellable, error)) - goto out; + return FALSE; - ret = TRUE; - out: - return ret; + return TRUE; }