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:
parent
7ed881baa7
commit
d0f40a6af8
|
|
@ -1505,30 +1505,28 @@ 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 =
|
||||||
|
|
@ -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 */
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue