[ostree] core: Add --print-packfile argument for show



commit 97e82447c6c69991a7a558b311c17fbc9c5e2c4d
Author: Colin Walters <walters verbum org>
Date:   Tue Nov 15 15:16:38 2011 -0500

    core: Add --print-packfile argument for show
    
    Just another debugging tool.

 src/ostree/ot-builtin-show.c |   53 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 2 deletions(-)
---
diff --git a/src/ostree/ot-builtin-show.c b/src/ostree/ot-builtin-show.c
index 3a2e9c3..0440cf3 100644
--- a/src/ostree/ot-builtin-show.c
+++ b/src/ostree/ot-builtin-show.c
@@ -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
@@ -94,6 +107,37 @@ show_repo_meta (OstreeRepo  *repo,
 }
 
 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,
                   const char *resolved_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;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]