ostree-sysroot: convert function to new style

Also convert ot-admin-builtin-deploy.c.
Prep for more work there.

Closes: #1110
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2017-08-22 17:10:54 -04:00 committed by Atomic Bot
parent 7ed881baa7
commit d0f40a6af8
2 changed files with 44 additions and 60 deletions

View File

@ -256,7 +256,7 @@ ensure_sysroot_fd (OstreeSysroot *self,
* Access a file descriptor that refers to the root directory of this * Access a file descriptor that refers to the root directory of this
* sysroot. ostree_sysroot_load() must have been invoked prior to * sysroot. ostree_sysroot_load() must have been invoked prior to
* calling this function. * calling this function.
* *
* Returns: A file descriptor valid for the lifetime of @self * Returns: A file descriptor valid for the lifetime of @self
*/ */
int int
@ -276,7 +276,7 @@ _ostree_sysroot_bump_mtime (OstreeSysroot *self,
glnx_set_prefix_error_from_errno (error, "%s", "futimens"); glnx_set_prefix_error_from_errno (error, "%s", "futimens");
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
/** /**
@ -894,7 +894,7 @@ ostree_sysroot_get_subbootversion (OstreeSysroot *self)
/** /**
* ostree_sysroot_get_booted_deployment: * ostree_sysroot_get_booted_deployment:
* @self: Sysroot * @self: Sysroot
* *
* Returns: (transfer none): The currently booted deployment, or %NULL if none * Returns: (transfer none): The currently booted deployment, or %NULL if none
*/ */
OstreeDeployment * OstreeDeployment *
@ -1377,7 +1377,7 @@ lock_in_thread (GTask *task,
* @cancellable: Cancellable * @cancellable: Cancellable
* @callback: Callback * @callback: Callback
* @user_data: User data * @user_data: User data
* *
* An asynchronous version of ostree_sysroot_lock(). * An asynchronous version of ostree_sysroot_lock().
*/ */
void void
@ -1395,7 +1395,7 @@ ostree_sysroot_lock_async (OstreeSysroot *self,
* @self: Self * @self: Self
* @result: Result * @result: Result
* @error: Error * @error: Error
* *
* Call when ostree_sysroot_lock_async() is ready. * Call when ostree_sysroot_lock_async() is ready.
*/ */
gboolean gboolean
@ -1413,7 +1413,7 @@ ostree_sysroot_lock_finish (OstreeSysroot *self,
* @osname: Name group of operating system checkouts * @osname: Name group of operating system checkouts
* @cancellable: Cancellable * @cancellable: Cancellable
* @error: Error * @error: Error
* *
* Initialize the directory structure for an "osname", which is a * Initialize the directory structure for an "osname", which is a
* group of operating system deployments, with a shared `/var`. One * group of operating system deployments, with a shared `/var`. One
* is required for generating a deployment. * is required for generating a deployment.
@ -1505,36 +1505,34 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; const gboolean postclean =
guint i; (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN) == 0;
OstreeDeployment *booted_deployment = NULL; const gboolean retain =
g_autoptr(GPtrArray) deployments = NULL; (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN) > 0;
g_autoptr(GPtrArray) new_deployments = g_ptr_array_new_with_free_func (g_object_unref); const gboolean make_default =
const gboolean postclean = (flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NO_CLEAN) == 0; !((flags & OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_NOT_DEFAULT) > 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;
deployments = ostree_sysroot_get_deployments (sysroot); g_autoptr(GPtrArray) deployments = ostree_sysroot_get_deployments (sysroot);
booted_deployment = ostree_sysroot_get_booted_deployment (sysroot); OstreeDeployment *booted_deployment = ostree_sysroot_get_booted_deployment (sysroot);
if (osname == NULL && booted_deployment) if (osname == NULL && booted_deployment)
osname = ostree_deployment_get_osname (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) if (make_default)
{ {
g_ptr_array_add (new_deployments, g_object_ref (new_deployment)); g_ptr_array_add (new_deployments, g_object_ref (new_deployment));
added_new = TRUE; added_new = TRUE;
} }
for (i = 0; i < deployments->len; i++) for (guint i = 0; i < deployments->len; i++)
{ {
OstreeDeployment *deployment = deployments->pdata[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, booted_deployment) ||
ostree_deployment_equal (deployment, merge_deployment); ostree_deployment_equal (deployment, merge_deployment);
/* Keep deployments with different osnames, as well as the /* Keep deployments with different osnames, as well as the
* booted and merge deployments * booted and merge deployments
*/ */
@ -1562,13 +1560,12 @@ ostree_sysroot_simple_write_deployment (OstreeSysroot *sysroot,
added_new = TRUE; added_new = TRUE;
} }
OstreeSysrootWriteDeploymentsOpts write_opts = { .do_postclean = postclean };
if (!ostree_sysroot_write_deployments_with_options (sysroot, new_deployments, &write_opts, if (!ostree_sysroot_write_deployments_with_options (sysroot, new_deployments, &write_opts,
cancellable, error)) cancellable, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }
/* Deploy a copy of @target_deployment */ /* Deploy a copy of @target_deployment */

View File

@ -57,64 +57,55 @@ static GOptionEntry options[] = {
gboolean gboolean
ot_admin_builtin_deploy (int argc, char **argv, GCancellable *cancellable, GError **error) 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; __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, if (!ostree_admin_option_context_parse (context, options, &argc, &argv,
OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER,
&sysroot, cancellable, error)) &sysroot, cancellable, error))
goto out; return FALSE;
if (argc < 2) if (argc < 2)
{ {
ot_util_usage_error (context, "REF/REV must be specified", error); 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)) if (!ostree_sysroot_load (sysroot, cancellable, error))
goto out; return FALSE;
OstreeRepo *repo = ostree_sysroot_repo (sysroot);
if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
goto out;
/* Find the currently booted deployment, if any; we will ensure it /* Find the currently booted deployment, if any; we will ensure it
* is present in the new deployment list. * is present in the new deployment list.
*/ */
if (!ot_admin_require_booted_deployment_or_osname (sysroot, opt_osname, if (!ot_admin_require_booted_deployment_or_osname (sysroot, opt_osname,
cancellable, error)) cancellable, error))
{ return glnx_prefix_error (error, "Looking for booted deployment");
g_prefix_error (error, "Looking for booted deployment: ");
goto out;
}
g_autoptr(GKeyFile) origin = NULL;
if (opt_origin_path) if (opt_origin_path)
{ {
origin = g_key_file_new (); origin = g_key_file_new ();
if (!g_key_file_load_from_file (origin, opt_origin_path, 0, error)) if (!g_key_file_load_from_file (origin, opt_origin_path, 0, error))
goto out; return FALSE;
} }
else else
{ {
origin = ostree_sysroot_origin_new_from_refspec (sysroot, refspec); origin = ostree_sysroot_origin_new_from_refspec (sysroot, refspec);
} }
g_autofree char *revision = NULL;
if (!ostree_repo_resolve_rev (repo, refspec, FALSE, &revision, error)) 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 /* Here we perform cleanup of any leftover data from previous
* partial failures. This avoids having to call * 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. * we find it.
*/ */
if (!ostree_sysroot_prepare_cleanup (sysroot, cancellable, error)) if (!ostree_sysroot_prepare_cleanup (sysroot, cancellable, error))
{ return glnx_prefix_error (error, "Performing initial cleanup");
g_prefix_error (error, "Performing initial cleanup: ");
goto out;
}
kargs = _ostree_kernel_args_new (); 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 (opt_kernel_proc_cmdline)
{ {
if (!_ostree_kernel_args_append_proc_cmdline (kargs, cancellable, error)) if (!_ostree_kernel_args_append_proc_cmdline (kargs, cancellable, error))
goto out; return FALSE;
} }
else if (merge_deployment) 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_auto(GStrv) kargs_strv = _ostree_kernel_args_to_strv (kargs);
g_autoptr(OstreeDeployment) new_deployment = NULL;
if (!ostree_sysroot_deploy_tree (sysroot, if (!ostree_sysroot_deploy_tree (sysroot,
opt_osname, revision, origin, opt_osname, revision, origin,
merge_deployment, kargs_strv, merge_deployment, kargs_strv,
&new_deployment, &new_deployment,
cancellable, error)) cancellable, error))
goto out; return FALSE;
} }
if (!ostree_sysroot_simple_write_deployment (sysroot, opt_osname, if (!ostree_sysroot_simple_write_deployment (sysroot, opt_osname,
new_deployment, merge_deployment, new_deployment, merge_deployment,
opt_retain ? OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN : 0, opt_retain ? OSTREE_SYSROOT_SIMPLE_WRITE_DEPLOYMENT_FLAGS_RETAIN : 0,
cancellable, error)) cancellable, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }