コード例 #1
0
ファイル: ot-builtin-show.c プロジェクト: mwleeds/ostree
static gboolean
do_print_variant_generic (const GVariantType *type,
                          const char *filename,
                          GError **error)
{
  g_autoptr(GVariant) variant = NULL;

  if (!ot_util_variant_map_at (AT_FDCWD, filename, type, TRUE, &variant, error))
    return FALSE;

  ot_dump_variant (variant);
  return TRUE;
}
コード例 #2
0
gboolean
_ostree_repo_static_delta_dump (OstreeRepo                    *self,
                                const char                    *delta_id,
                                GCancellable                  *cancellable,
                                GError                       **error)
{
  gboolean ret = FALSE;
  g_autofree char *from = NULL; 
  g_autofree char *to = NULL;
  g_autofree char *superblock_path = NULL;
  g_autoptr(GVariant) delta_superblock = NULL;
  guint64 total_size = 0, total_usize = 0;
  guint64 total_fallback_size = 0, total_fallback_usize = 0;
  guint i;
  OstreeDeltaEndianness endianness;
  gboolean swap_endian = FALSE;

  if (!_ostree_parse_delta_name (delta_id, &from, &to, error))
    goto out;

  superblock_path = _ostree_get_relative_static_delta_superblock_path (from, to);

  if (!ot_util_variant_map_at (self->repo_dir_fd, superblock_path,
                               (GVariantType*)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT,
                               OT_VARIANT_MAP_TRUSTED, &delta_superblock, error))
    goto out;

  g_print ("Delta: %s\n", delta_id);
  { const char *endianness_description;
    gboolean was_heuristic;

    endianness = _ostree_delta_get_endianness (delta_superblock, &was_heuristic);

    switch (endianness)
      {
      case OSTREE_DELTA_ENDIAN_BIG:
        if (was_heuristic)
          endianness_description = "big (heuristic)";
        else
          endianness_description = "big";
        if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
          swap_endian = TRUE;
        break;
      case OSTREE_DELTA_ENDIAN_LITTLE:
        if (was_heuristic)
          endianness_description = "little (heuristic)";
        else
          endianness_description = "little";
        if (G_BYTE_ORDER == G_BIG_ENDIAN)
          swap_endian = TRUE;
        break;
      case OSTREE_DELTA_ENDIAN_INVALID:
        endianness_description = "invalid";
        break;
      default:
        g_assert_not_reached ();
      }
    
    g_print ("Endianness: %s\n", endianness_description);
  }
  { guint64 ts;
    g_variant_get_child (delta_superblock, 1, "t", &ts);
    g_print ("Timestamp: %" G_GUINT64_FORMAT "\n", GUINT64_FROM_BE (ts));
  }
  { g_autoptr(GVariant) recurse = NULL;
    g_variant_get_child (delta_superblock, 5, "@ay", &recurse);
    g_print ("Number of parents: %u\n", (guint)(g_variant_get_size (recurse) / (OSTREE_SHA256_DIGEST_LEN * 2)));
  }
  { g_autoptr(GVariant) fallback = NULL;
    guint n_fallback;

    g_variant_get_child (delta_superblock, 7, "@a" OSTREE_STATIC_DELTA_FALLBACK_FORMAT, &fallback);
    n_fallback = g_variant_n_children (fallback);

    g_print ("Number of fallback entries: %u\n", n_fallback);

    for (i = 0; i < n_fallback; i++)
      {
        guint64 size, usize;
        g_autoptr(GVariant) checksum_v = NULL;
        char checksum[OSTREE_SHA256_STRING_LEN+1];
        g_variant_get_child (fallback, i, "(y@aytt)", NULL, &checksum_v, &size, &usize);
        ostree_checksum_inplace_from_bytes (ostree_checksum_bytes_peek (checksum_v), checksum);
        size = maybe_swap_endian_u64 (swap_endian, size);
        usize = maybe_swap_endian_u64 (swap_endian, usize);
        g_print ("  %s\n", checksum);
        total_fallback_size += size;
        total_fallback_usize += usize;
      }
    { g_autofree char *sizestr = g_format_size (total_fallback_size);
      g_autofree char *usizestr = g_format_size (total_fallback_usize);
      g_print ("Total Fallback Size: %" G_GUINT64_FORMAT " (%s)\n", total_fallback_size, sizestr);
      g_print ("Total Fallback Uncompressed Size: %" G_GUINT64_FORMAT " (%s)\n", total_fallback_usize, usizestr);
    }
  }
  { g_autoptr(GVariant) meta_entries = NULL;
    guint n_parts;

    g_variant_get_child (delta_superblock, 6, "@a" OSTREE_STATIC_DELTA_META_ENTRY_FORMAT, &meta_entries);
    n_parts = g_variant_n_children (meta_entries);
    g_print ("Number of parts: %u\n", n_parts);

    for (i = 0; i < n_parts; i++)
      {
        if (!show_one_part (self, swap_endian, from, to, meta_entries, i,
                            &total_size, &total_usize,
                            cancellable, error))
          goto out;
      }
  }

  { g_autofree char *sizestr = g_format_size (total_size);
    g_autofree char *usizestr = g_format_size (total_usize);
    g_print ("Total Part Size: %" G_GUINT64_FORMAT " (%s)\n", total_size, sizestr);
    g_print ("Total Part Uncompressed Size: %" G_GUINT64_FORMAT " (%s)\n", total_usize, usizestr);
  }
  { guint64 overall_size = total_size + total_fallback_size;
    guint64 overall_usize = total_usize + total_fallback_usize;
    g_autofree char *sizestr = g_format_size (overall_size);
    g_autofree char *usizestr = g_format_size (overall_usize);
    g_print ("Total Size: %" G_GUINT64_FORMAT " (%s)\n", overall_size, sizestr);
    g_print ("Total Uncompressed Size: %" G_GUINT64_FORMAT " (%s)\n", overall_usize, usizestr);
  }

  ret = TRUE;
 out:
  return ret;
}