mirror of
https://github.com/ostreedev/ostree.git
synced 2025-03-19 22:50:35 +03:00
core: Add --print-packfile argument for show
Just another debugging tool.
This commit is contained in:
parent
d196a47043
commit
97e82447c6
@ -27,10 +27,12 @@
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
static gboolean print_packfile;
|
||||
static gboolean print_compose;
|
||||
static char* print_variant_type;
|
||||
|
||||
static GOptionEntry options[] = {
|
||||
{ "print-packfile", 0, 0, G_OPTION_ARG_NONE, &print_packfile, "If given, argument given is a packfile", NULL },
|
||||
{ "print-compose", 0, 0, G_OPTION_ARG_NONE, &print_compose, "If given, show the branches which make up the given compose commit", NULL },
|
||||
{ "print-variant-type", 0, 0, G_OPTION_ARG_STRING, &print_variant_type, "If given, argument should be a filename and it will be interpreted as this type", NULL },
|
||||
{ NULL }
|
||||
@ -40,11 +42,22 @@ static void
|
||||
print_variant (GVariant *variant)
|
||||
{
|
||||
char *formatted_variant = NULL;
|
||||
GVariant *byteswapped = NULL;
|
||||
|
||||
formatted_variant = g_variant_print (variant, TRUE);
|
||||
if (G_BYTE_ORDER != G_BIG_ENDIAN)
|
||||
{
|
||||
byteswapped = g_variant_byteswap (variant);
|
||||
formatted_variant = g_variant_print (byteswapped, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
formatted_variant = g_variant_print (variant, TRUE);
|
||||
}
|
||||
g_print ("%s\n", formatted_variant);
|
||||
|
||||
g_free (formatted_variant);
|
||||
if (byteswapped)
|
||||
g_variant_unref (byteswapped);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -93,6 +106,37 @@ show_repo_meta (OstreeRepo *repo,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
do_print_packfile (OstreeRepo *repo,
|
||||
const char *checksum,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GVariant *variant = NULL;
|
||||
char *path = NULL;
|
||||
GInputStream *content = NULL;
|
||||
GFile *file = NULL;
|
||||
|
||||
path = ostree_repo_get_object_path (repo, checksum, OSTREE_OBJECT_TYPE_FILE);
|
||||
if (!path)
|
||||
goto out;
|
||||
file = ot_util_new_file_for_path (path);
|
||||
|
||||
if (!ostree_parse_packed_file (file, &variant, &content, NULL, error))
|
||||
goto out;
|
||||
|
||||
print_variant (variant);
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
g_free (path);
|
||||
g_clear_object (&file);
|
||||
g_clear_object (&content);
|
||||
if (variant)
|
||||
g_variant_unref (variant);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
do_print_compose (OstreeRepo *repo,
|
||||
const char *rev,
|
||||
@ -165,7 +209,12 @@ ostree_builtin_show (int argc, char **argv, const char *repo_path, GError **erro
|
||||
if (argc > 1)
|
||||
rev = argv[1];
|
||||
|
||||
if (print_compose)
|
||||
if (print_packfile)
|
||||
{
|
||||
if (!do_print_packfile (repo, rev, error))
|
||||
goto out;
|
||||
}
|
||||
else if (print_compose)
|
||||
{
|
||||
if (!ostree_repo_resolve_rev (repo, rev, &resolved_rev, error))
|
||||
goto out;
|
||||
|
Loading…
x
Reference in New Issue
Block a user