From 8d5b8dd740452111dd9bd8e83545a21d1cf0916a Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 29 Jul 2013 18:44:41 -0400 Subject: [PATCH] admin: Clean up builtin prototype Pass through GCancellable, and just use GFile *sysroot, since that's all OtAdminBuiltinOpts was. --- src/ostree/ot-admin-builtin-cleanup.c | 5 ++--- src/ostree/ot-admin-builtin-deploy.c | 4 +--- src/ostree/ot-admin-builtin-diff.c | 11 +++++------ src/ostree/ot-admin-builtin-init-fs.c | 3 +-- src/ostree/ot-admin-builtin-os-init.c | 7 +++---- src/ostree/ot-admin-builtin-status.c | 9 ++++----- src/ostree/ot-admin-builtin-undeploy.c | 4 +--- src/ostree/ot-admin-builtin-upgrade.c | 14 ++++++-------- src/ostree/ot-admin-builtins.h | 22 +++++++++------------- src/ostree/ot-builtin-admin.c | 8 ++++---- 10 files changed, 36 insertions(+), 51 deletions(-) diff --git a/src/ostree/ot-admin-builtin-cleanup.c b/src/ostree/ot-admin-builtin-cleanup.c index b8e8f302..8b08ed28 100644 --- a/src/ostree/ot-admin-builtin-cleanup.c +++ b/src/ostree/ot-admin-builtin-cleanup.c @@ -34,11 +34,10 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_cleanup (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error) +ot_admin_builtin_cleanup (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error) { GOptionContext *context; gboolean ret = FALSE; - __attribute__((unused)) GCancellable *cancellable = NULL; context = g_option_context_new ("Delete untagged deployments and repository objects"); @@ -47,7 +46,7 @@ ot_admin_builtin_cleanup (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, if (!g_option_context_parse (context, &argc, &argv, error)) goto out; - if (!ot_admin_cleanup (admin_opts->sysroot, cancellable, error)) + if (!ot_admin_cleanup (sysroot, cancellable, error)) goto out; ret = TRUE; diff --git a/src/ostree/ot-admin-builtin-deploy.c b/src/ostree/ot-admin-builtin-deploy.c index bc8dca84..6652f56a 100644 --- a/src/ostree/ot-admin-builtin-deploy.c +++ b/src/ostree/ot-admin-builtin-deploy.c @@ -47,13 +47,11 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error) +ot_admin_builtin_deploy (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - __attribute__((unused)) GCancellable *cancellable = NULL; const char *refspec; GOptionContext *context; - GFile *sysroot = admin_opts->sysroot; GKeyFile *origin = NULL; int current_bootversion; int new_bootversion; diff --git a/src/ostree/ot-admin-builtin-diff.c b/src/ostree/ot-admin-builtin-diff.c index 8965a3d8..eb0a40db 100644 --- a/src/ostree/ot-admin-builtin-diff.c +++ b/src/ostree/ot-admin-builtin-diff.c @@ -37,7 +37,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_diff (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error) +ot_admin_builtin_diff (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error) { GOptionContext *context; gboolean ret = FALSE; @@ -52,7 +52,6 @@ ot_admin_builtin_diff (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GE gs_unref_ptrarray GPtrArray *deployments = NULL; gs_unref_object GFile *orig_etc_path = NULL; gs_unref_object GFile *new_etc_path = NULL; - __attribute__((unused)) GCancellable *cancellable = NULL; int bootversion; context = g_option_context_new ("Diff current /etc configuration versus default"); @@ -62,16 +61,16 @@ ot_admin_builtin_diff (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GE if (!g_option_context_parse (context, &argc, &argv, error)) goto out; - repo_path = g_file_resolve_relative_path (admin_opts->sysroot, "ostree/repo"); + repo_path = g_file_resolve_relative_path (sysroot, "ostree/repo"); - if (!ot_admin_list_deployments (admin_opts->sysroot, &bootversion, &deployments, + if (!ot_admin_list_deployments (sysroot, &bootversion, &deployments, cancellable, error)) { g_prefix_error (error, "While listing deployments: "); goto out; } - if (!ot_admin_require_deployment_or_osname (admin_opts->sysroot, deployments, + if (!ot_admin_require_deployment_or_osname (sysroot, deployments, opt_osname, &deployment, cancellable, error)) goto out; @@ -86,7 +85,7 @@ ot_admin_builtin_diff (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GE goto out; } - deployment_dir = ot_admin_get_deployment_directory (admin_opts->sysroot, deployment); + deployment_dir = ot_admin_get_deployment_directory (sysroot, deployment); orig_etc_path = g_file_resolve_relative_path (deployment_dir, "usr/etc"); new_etc_path = g_file_resolve_relative_path (deployment_dir, "etc"); diff --git a/src/ostree/ot-admin-builtin-init-fs.c b/src/ostree/ot-admin-builtin-init-fs.c index 9b00814a..dbfd0ba7 100644 --- a/src/ostree/ot-admin-builtin-init-fs.c +++ b/src/ostree/ot-admin-builtin-init-fs.c @@ -34,7 +34,7 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_init_fs (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error) +ot_admin_builtin_init_fs (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error) { GOptionContext *context; gboolean ret = FALSE; @@ -42,7 +42,6 @@ ot_admin_builtin_init_fs (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, gs_unref_object GFile *child = NULL; guint i; const char *normal_toplevels[] = {"boot", "dev", "home", "proc", "run", "sys"}; - GCancellable *cancellable = NULL; context = g_option_context_new ("PATH - Initialize a root filesystem"); g_option_context_add_main_entries (context, options, NULL); diff --git a/src/ostree/ot-admin-builtin-os-init.c b/src/ostree/ot-admin-builtin-os-init.c index ddb641fd..b9e85709 100644 --- a/src/ostree/ot-admin-builtin-os-init.c +++ b/src/ostree/ot-admin-builtin-os-init.c @@ -34,14 +34,13 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_os_init (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error) +ot_admin_builtin_os_init (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error) { GOptionContext *context; gboolean ret = FALSE; const char *osname = NULL; gs_unref_object GFile *deploy_dir = NULL; gs_unref_object GFile *dir = NULL; - __attribute__((unused)) GCancellable *cancellable = NULL; context = g_option_context_new ("OSNAME - Initialize empty state for given operating system"); g_option_context_add_main_entries (context, options, NULL); @@ -49,7 +48,7 @@ ot_admin_builtin_os_init (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, if (!g_option_context_parse (context, &argc, &argv, error)) goto out; - if (!ot_admin_ensure_initialized (admin_opts->sysroot, cancellable, error)) + if (!ot_admin_ensure_initialized (sysroot, cancellable, error)) goto out; if (argc < 2) @@ -60,7 +59,7 @@ ot_admin_builtin_os_init (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, osname = argv[1]; - deploy_dir = ot_gfile_get_child_build_path (admin_opts->sysroot, "ostree", "deploy", osname, NULL); + deploy_dir = ot_gfile_get_child_build_path (sysroot, "ostree", "deploy", osname, NULL); /* Ensure core subdirectories of /var exist, since we need them for * dracut generation, and the host will want them too. Note that at diff --git a/src/ostree/ot-admin-builtin-status.c b/src/ostree/ot-admin-builtin-status.c index fe6c407f..eb5b7659 100644 --- a/src/ostree/ot-admin-builtin-status.c +++ b/src/ostree/ot-admin-builtin-status.c @@ -34,14 +34,13 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_status (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error) +ot_admin_builtin_status (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error) { GOptionContext *context; gboolean ret = FALSE; int bootversion; gs_unref_object OtDeployment *booted_deployment = NULL; gs_unref_ptrarray GPtrArray *deployments = NULL; - __attribute__((unused)) GCancellable *cancellable = NULL; guint i; context = g_option_context_new ("List deployments"); @@ -51,14 +50,14 @@ ot_admin_builtin_status (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, if (!g_option_context_parse (context, &argc, &argv, error)) goto out; - if (!ot_admin_list_deployments (admin_opts->sysroot, &bootversion, &deployments, + if (!ot_admin_list_deployments (sysroot, &bootversion, &deployments, cancellable, error)) { g_prefix_error (error, "While listing deployments: "); goto out; } - if (!ot_admin_find_booted_deployment (admin_opts->sysroot, deployments, + if (!ot_admin_find_booted_deployment (sysroot, deployments, &booted_deployment, cancellable, error)) goto out; @@ -71,7 +70,7 @@ ot_admin_builtin_status (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, { int subbootversion; - if (!ot_admin_read_current_subbootversion (admin_opts->sysroot, bootversion, + if (!ot_admin_read_current_subbootversion (sysroot, bootversion, &subbootversion, cancellable, error)) goto out; diff --git a/src/ostree/ot-admin-builtin-undeploy.c b/src/ostree/ot-admin-builtin-undeploy.c index 0b5579c9..28f43638 100644 --- a/src/ostree/ot-admin-builtin-undeploy.c +++ b/src/ostree/ot-admin-builtin-undeploy.c @@ -34,11 +34,9 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_undeploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error) +ot_admin_builtin_undeploy (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - __attribute__((unused)) GCancellable *cancellable = NULL; - GFile *sysroot = admin_opts->sysroot; GOptionContext *context; const char *deploy_index_str; int deploy_index; diff --git a/src/ostree/ot-admin-builtin-upgrade.c b/src/ostree/ot-admin-builtin-upgrade.c index b5b4e93d..2b56be39 100644 --- a/src/ostree/ot-admin-builtin-upgrade.c +++ b/src/ostree/ot-admin-builtin-upgrade.c @@ -43,12 +43,10 @@ static GOptionEntry options[] = { }; gboolean -ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error) +ot_admin_builtin_upgrade (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - __attribute__((unused)) GCancellable *cancellable = NULL; GOptionContext *context; - GFile *sysroot = admin_opts->sysroot; gs_free char *booted_osname = NULL; gs_unref_object OstreeRepo *repo = NULL; gs_unref_object GFile *repo_path = NULL; @@ -74,7 +72,7 @@ ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, if (!g_option_context_parse (context, &argc, &argv, error)) goto out; - if (!ot_admin_list_deployments (admin_opts->sysroot, ¤t_bootversion, + if (!ot_admin_list_deployments (sysroot, ¤t_bootversion, ¤t_deployments, cancellable, error)) { @@ -82,7 +80,7 @@ ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, goto out; } - if (!ot_admin_require_deployment_or_osname (admin_opts->sysroot, current_deployments, + if (!ot_admin_require_deployment_or_osname (sysroot, current_deployments, opt_osname, &booted_deployment, cancellable, error)) @@ -92,10 +90,10 @@ ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, merge_deployment = ot_admin_get_merge_deployment (current_deployments, opt_osname, booted_deployment); - deployment_path = ot_admin_get_deployment_directory (admin_opts->sysroot, merge_deployment); + deployment_path = ot_admin_get_deployment_directory (sysroot, merge_deployment); deployment_origin_path = ot_admin_get_deployment_origin_path (deployment_path); - repo_path = g_file_resolve_relative_path (admin_opts->sysroot, "ostree/repo"); + repo_path = g_file_resolve_relative_path (sysroot, "ostree/repo"); repo = ostree_repo_new (repo_path); if (!ostree_repo_check (repo, error)) goto out; @@ -139,7 +137,7 @@ ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, else { gs_unref_object GFile *real_sysroot = g_file_new_for_path ("/"); - if (!ot_admin_deploy (admin_opts->sysroot, + if (!ot_admin_deploy (sysroot, current_bootversion, current_deployments, opt_osname, new_revision, origin, NULL, FALSE, diff --git a/src/ostree/ot-admin-builtins.h b/src/ostree/ot-admin-builtins.h index 440ba0f4..bc7b8fc4 100644 --- a/src/ostree/ot-admin-builtins.h +++ b/src/ostree/ot-admin-builtins.h @@ -26,19 +26,15 @@ G_BEGIN_DECLS -typedef struct { - GFile *sysroot; -} OtAdminBuiltinOpts; - -gboolean ot_admin_builtin_os_init (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error); -gboolean ot_admin_builtin_install (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error); -gboolean ot_admin_builtin_init_fs (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error); -gboolean ot_admin_builtin_undeploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error); -gboolean ot_admin_builtin_deploy (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error); -gboolean ot_admin_builtin_cleanup (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error); -gboolean ot_admin_builtin_status (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error); -gboolean ot_admin_builtin_diff (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error); -gboolean ot_admin_builtin_upgrade (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error); +gboolean ot_admin_builtin_os_init (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error); +gboolean ot_admin_builtin_install (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error); +gboolean ot_admin_builtin_init_fs (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error); +gboolean ot_admin_builtin_undeploy (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error); +gboolean ot_admin_builtin_deploy (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error); +gboolean ot_admin_builtin_cleanup (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error); +gboolean ot_admin_builtin_status (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error); +gboolean ot_admin_builtin_diff (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error); +gboolean ot_admin_builtin_upgrade (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error); G_END_DECLS diff --git a/src/ostree/ot-builtin-admin.c b/src/ostree/ot-builtin-admin.c index 9b5bdc45..e6aaee68 100644 --- a/src/ostree/ot-builtin-admin.c +++ b/src/ostree/ot-builtin-admin.c @@ -34,7 +34,7 @@ typedef struct { const char *name; - gboolean (*fn) (int argc, char **argv, OtAdminBuiltinOpts *admin_opts, GError **error); + gboolean (*fn) (int argc, char **argv, GFile *sysroot, GCancellable *cancellable, GError **error); } OstreeAdminCommand; static OstreeAdminCommand admin_subcommands[] = { @@ -57,7 +57,7 @@ ostree_builtin_admin (int argc, char **argv, GFile *repo_path, GCancellable *can const char *subcommand_name; OstreeAdminCommand *subcommand; int subcmd_argc; - OtAdminBuiltinOpts admin_opts; + gs_unref_object GFile *sysroot = NULL; char **subcmd_argv = NULL; if (argc > 1 && g_str_has_prefix (argv[1], "--sysroot=")) @@ -98,8 +98,8 @@ ostree_builtin_admin (int argc, char **argv, GFile *repo_path, GCancellable *can ostree_prep_builtin_argv (subcommand_name, argc-2, argv+2, &subcmd_argc, &subcmd_argv); - admin_opts.sysroot = g_file_new_for_path (opt_sysroot); - if (!subcommand->fn (subcmd_argc, subcmd_argv, &admin_opts, error)) + sysroot = g_file_new_for_path (opt_sysroot); + if (!subcommand->fn (subcmd_argc, subcmd_argv, sysroot, cancellable, error)) goto out; ret = TRUE;