bin: Port a few commands (diff,remote,static-delta) to new style

No functional changes, not prep for anything, just keeping up some momentum.

Closes: #1344
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-11-15 18:04:31 -05:00 committed by Atomic Bot
parent 20996d0da3
commit 23db56f9c3
3 changed files with 60 additions and 102 deletions

View File

@ -43,29 +43,20 @@ static GOptionEntry options[] = {
gboolean gboolean
ot_admin_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) ot_admin_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
{ {
g_autoptr(GOptionContext) context = NULL; g_autoptr(GOptionContext) context = g_option_context_new ("");
g_autoptr(OstreeSysroot) sysroot = NULL;
gboolean ret = FALSE;
g_autoptr(OstreeDeployment) deployment = NULL;
g_autoptr(GFile) deployment_dir = NULL;
g_autoptr(GPtrArray) modified = NULL;
g_autoptr(GPtrArray) removed = NULL;
g_autoptr(GPtrArray) added = NULL;
g_autoptr(GFile) orig_etc_path = NULL;
g_autoptr(GFile) new_etc_path = NULL;
context = g_option_context_new ("");
g_option_context_add_main_entries (context, options, NULL); g_option_context_add_main_entries (context, options, NULL);
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_UNLOCKED, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED,
invocation, &sysroot, cancellable, error)) invocation, &sysroot, cancellable, error))
goto out; return FALSE;
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))
goto out; return FALSE;
g_autoptr(OstreeDeployment) deployment = NULL;
if (opt_osname != NULL) if (opt_osname != NULL)
{ {
deployment = ostree_sysroot_get_merge_deployment (sysroot, opt_osname); deployment = ostree_sysroot_get_merge_deployment (sysroot, opt_osname);
@ -73,28 +64,24 @@ ot_admin_builtin_diff (int argc, char **argv, OstreeCommandInvocation *invocatio
{ {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
"No deployment for OS '%s'", opt_osname); "No deployment for OS '%s'", opt_osname);
goto out; return FALSE;
} }
} }
else else
deployment = g_object_ref (ostree_sysroot_get_booted_deployment (sysroot)); deployment = g_object_ref (ostree_sysroot_get_booted_deployment (sysroot));
deployment_dir = ostree_sysroot_get_deployment_directory (sysroot, deployment); g_autoptr(GFile) deployment_dir = ostree_sysroot_get_deployment_directory (sysroot, deployment);
g_autoptr(GFile) orig_etc_path = g_file_resolve_relative_path (deployment_dir, "usr/etc");
orig_etc_path = g_file_resolve_relative_path (deployment_dir, "usr/etc"); g_autoptr(GFile) new_etc_path = g_file_resolve_relative_path (deployment_dir, "etc");
new_etc_path = g_file_resolve_relative_path (deployment_dir, "etc"); g_autoptr(GPtrArray) modified = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_diff_item_unref);
g_autoptr(GPtrArray) removed = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
modified = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_diff_item_unref); g_autoptr(GPtrArray) added = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
removed = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
added = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
if (!ostree_diff_dirs (OSTREE_DIFF_FLAGS_IGNORE_XATTRS, if (!ostree_diff_dirs (OSTREE_DIFF_FLAGS_IGNORE_XATTRS,
orig_etc_path, new_etc_path, modified, removed, added, orig_etc_path, new_etc_path, modified, removed, added,
cancellable, error)) cancellable, error))
goto out; return FALSE;
ostree_diff_print (orig_etc_path, new_etc_path, modified, removed, added); ostree_diff_print (orig_etc_path, new_etc_path, modified, removed, added);
ret = TRUE; return TRUE;
out:
return ret;
} }

View File

@ -86,12 +86,8 @@ remote_option_context_new_with_commands (void)
gboolean gboolean
ostree_builtin_remote (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) ostree_builtin_remote (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
{ {
OstreeCommand *subcommand;
const char *subcommand_name = NULL; const char *subcommand_name = NULL;
g_autofree char *prgname = NULL;
gboolean ret = FALSE;
int in,out; int in,out;
for (in = 1, out = 1; in < argc; in++, out++) for (in = 1, out = 1; in < argc; in++, out++)
{ {
/* The non-option is the command, take it out of the arguments */ /* The non-option is the command, take it out of the arguments */
@ -115,7 +111,7 @@ ostree_builtin_remote (int argc, char **argv, OstreeCommandInvocation *invocatio
argc = out; argc = out;
subcommand = remote_subcommands; OstreeCommand *subcommand = remote_subcommands;
while (subcommand->name) while (subcommand->name)
{ {
if (g_strcmp0 (subcommand_name, subcommand->name) == 0) if (g_strcmp0 (subcommand_name, subcommand->name) == 0)
@ -150,18 +146,15 @@ ostree_builtin_remote (int argc, char **argv, OstreeCommandInvocation *invocatio
help = g_option_context_get_help (context, FALSE, NULL); help = g_option_context_get_help (context, FALSE, NULL);
g_printerr ("%s", help); g_printerr ("%s", help);
goto out; return FALSE;
} }
prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name); g_autofree char *prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name);
g_set_prgname (prgname); g_set_prgname (prgname);
OstreeCommandInvocation sub_invocation = { .command = subcommand }; OstreeCommandInvocation sub_invocation = { .command = subcommand };
if (!subcommand->fn (argc, argv, &sub_invocation, cancellable, error)) if (!subcommand->fn (argc, argv, &sub_invocation, cancellable, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }

View File

@ -149,77 +149,63 @@ ot_static_delta_builtin_list (int argc, char **argv, OstreeCommandInvocation *in
static gboolean static gboolean
ot_static_delta_builtin_show (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) ot_static_delta_builtin_show (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
{ {
gboolean ret = FALSE;
g_autoptr(GOptionContext) context = NULL; g_autoptr(GOptionContext) context = g_option_context_new ("");
g_autoptr(OstreeRepo) repo = NULL; g_autoptr(OstreeRepo) repo = NULL;
const char *delta_id = NULL;
context = g_option_context_new ("");
if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, cancellable, error)) if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, cancellable, error))
goto out; return FALSE;
if (argc < 3) if (argc < 3)
{ {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"DELTA must be specified"); "DELTA must be specified");
goto out; return FALSE;
} }
delta_id = argv[2]; const char *delta_id = argv[2];
if (!ostree_cmd__private__ ()->ostree_static_delta_dump (repo, delta_id, cancellable, error)) if (!ostree_cmd__private__ ()->ostree_static_delta_dump (repo, delta_id, cancellable, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }
static gboolean static gboolean
ot_static_delta_builtin_delete (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) ot_static_delta_builtin_delete (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
{ {
gboolean ret = FALSE; g_autoptr(GOptionContext) context = g_option_context_new ("");
g_autoptr(GOptionContext) context = NULL;
g_autoptr(OstreeRepo) repo = NULL; g_autoptr(OstreeRepo) repo = NULL;
const char *delta_id = NULL;
context = g_option_context_new ("");
if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, cancellable, error)) if (!ostree_option_context_parse (context, list_options, &argc, &argv, invocation, &repo, cancellable, error))
goto out; return FALSE;
if (argc < 3) if (argc < 3)
{ {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"DELTA must be specified"); "DELTA must be specified");
goto out; return FALSE;
} }
delta_id = argv[2]; const char *delta_id = argv[2];
if (!ostree_cmd__private__ ()->ostree_static_delta_delete (repo, delta_id, cancellable, error)) if (!ostree_cmd__private__ ()->ostree_static_delta_delete (repo, delta_id, cancellable, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }
static gboolean static gboolean
ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
{ {
gboolean ret = FALSE; g_autoptr(GOptionContext) context = g_option_context_new ("[TO]");
g_autoptr(GOptionContext) context = NULL;
g_autoptr(OstreeRepo) repo = NULL; g_autoptr(OstreeRepo) repo = NULL;
context = g_option_context_new ("[TO]");
if (!ostree_option_context_parse (context, generate_options, &argc, &argv, invocation, &repo, cancellable, error)) if (!ostree_option_context_parse (context, generate_options, &argc, &argv, invocation, &repo, cancellable, error))
goto out; return FALSE;
if (!ostree_ensure_repo_writable (repo, error)) if (!ostree_ensure_repo_writable (repo, error))
goto out; return FALSE;
if (argc >= 3 && opt_to_rev == NULL) if (argc >= 3 && opt_to_rev == NULL)
opt_to_rev = argv[2]; opt_to_rev = argv[2];
@ -228,7 +214,7 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation
{ {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"TO revision must be specified"); "TO revision must be specified");
goto out; return FALSE;
} }
else else
{ {
@ -247,7 +233,7 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation
{ {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Cannot specify both --empty and --from=REV"); "Cannot specify both --empty and --from=REV");
goto out; return FALSE;
} }
from_source = NULL; from_source = NULL;
} }
@ -264,22 +250,21 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation
if (from_source) if (from_source)
{ {
if (!ostree_repo_resolve_rev (repo, from_source, FALSE, &from_resolved, error)) if (!ostree_repo_resolve_rev (repo, from_source, FALSE, &from_resolved, error))
goto out; return FALSE;
} }
if (!ostree_repo_resolve_rev (repo, opt_to_rev, FALSE, &to_resolved, error)) if (!ostree_repo_resolve_rev (repo, opt_to_rev, FALSE, &to_resolved, error))
goto out; return FALSE;
if (opt_if_not_exists) if (opt_if_not_exists)
{ {
gboolean does_exist; gboolean does_exist;
g_autofree char *delta_id = from_resolved ? g_strconcat (from_resolved, "-", to_resolved, NULL) : g_strdup (to_resolved); g_autofree char *delta_id = from_resolved ? g_strconcat (from_resolved, "-", to_resolved, NULL) : g_strdup (to_resolved);
if (!ostree_cmd__private__ ()->ostree_static_delta_query_exists (repo, delta_id, &does_exist, cancellable, error)) if (!ostree_cmd__private__ ()->ostree_static_delta_query_exists (repo, delta_id, &does_exist, cancellable, error))
goto out; return FALSE;
if (does_exist) if (does_exist)
{ {
g_print ("Delta %s already exists.\n", delta_id); g_print ("Delta %s already exists.\n", delta_id);
ret = TRUE; return TRUE;
goto out;
} }
} }
@ -293,7 +278,7 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation
{ {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Invalid endianness '%s'", opt_endianness); "Invalid endianness '%s'", opt_endianness);
goto out; return FALSE;
} }
} }
else else
@ -346,54 +331,47 @@ ot_static_delta_builtin_generate (int argc, char **argv, OstreeCommandInvocation
from_resolved, to_resolved, NULL, from_resolved, to_resolved, NULL,
params, params,
cancellable, error)) cancellable, error))
goto out; return FALSE;
} }
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
static gboolean static gboolean
ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) ot_static_delta_builtin_apply_offline (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error)
{ {
gboolean ret = FALSE;
const char *patharg;
g_autoptr(GFile) path = NULL;
g_autoptr(GOptionContext) context = NULL; g_autoptr(GOptionContext) context = NULL;
g_autoptr(OstreeRepo) repo = NULL; g_autoptr(OstreeRepo) repo = NULL;
context = g_option_context_new (""); context = g_option_context_new ("");
if (!ostree_option_context_parse (context, apply_offline_options, &argc, &argv, invocation, &repo, cancellable, error)) if (!ostree_option_context_parse (context, apply_offline_options, &argc, &argv, invocation, &repo, cancellable, error))
goto out; return FALSE;
if (!ostree_ensure_repo_writable (repo, error)) if (!ostree_ensure_repo_writable (repo, error))
goto out; return FALSE;
if (argc < 3) if (argc < 3)
{ {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"PATH must be specified"); "PATH must be specified");
goto out; return FALSE;
} }
patharg = argv[2]; const char *patharg = argv[2];
path = g_file_new_for_path (patharg); g_autoptr(GFile) path = g_file_new_for_path (patharg);
if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error)) if (!ostree_repo_prepare_transaction (repo, NULL, cancellable, error))
goto out; return FALSE;
if (!ostree_repo_static_delta_execute_offline (repo, path, FALSE, cancellable, error)) if (!ostree_repo_static_delta_execute_offline (repo, path, FALSE, cancellable, error))
goto out; return FALSE;
if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error)) if (!ostree_repo_commit_transaction (repo, NULL, cancellable, error))
goto out; return FALSE;
ret = TRUE; return TRUE;
out:
return ret;
} }
gboolean gboolean