core: Drop wrapping of metadata variants

This commit is contained in:
Colin Walters 2012-04-10 08:30:51 -04:00
parent 5a82b141ae
commit fa4cbc8b89
9 changed files with 46 additions and 126 deletions

View File

@ -31,6 +31,24 @@
#define ALIGN_VALUE(this, boundary) \
(( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))
const GVariantType *
ostree_metadata_variant_type (OstreeObjectType objtype)
{
switch (objtype)
{
case OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META:
return OSTREE_ARCHIVED_FILE_VARIANT_FORMAT;
case OSTREE_OBJECT_TYPE_DIR_TREE:
return OSTREE_TREE_GVARIANT_FORMAT;
case OSTREE_OBJECT_TYPE_DIR_META:
return OSTREE_DIRMETA_GVARIANT_FORMAT;
case OSTREE_OBJECT_TYPE_COMMIT:
return OSTREE_COMMIT_GVARIANT_FORMAT;
default:
g_assert_not_reached ();
}
}
gboolean
ostree_validate_checksum_string (const char *sha256,
GError **error)
@ -60,13 +78,6 @@ ostree_validate_rev (const char *rev,
return ret;
}
GVariant *
ostree_wrap_metadata_variant (OstreeObjectType type,
GVariant *metadata)
{
return g_variant_new ("(uv)", GUINT32_TO_BE ((guint32)type), metadata);
}
void
ostree_checksum_update_stat (GChecksum *checksum, guint32 uid, guint32 gid, guint32 mode)
{
@ -219,7 +230,6 @@ ostree_checksum_file_from_input (GFileInfo *file_info,
gsize bytes_read;
guint32 mode;
ot_lvariant GVariant *dirmeta = NULL;
ot_lvariant GVariant *packed = NULL;
GChecksum *ret_checksum = NULL;
if (OSTREE_OBJECT_TYPE_IS_META (objtype))
@ -232,9 +242,8 @@ ostree_checksum_file_from_input (GFileInfo *file_info,
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
{
dirmeta = ostree_create_directory_metadata (file_info, xattrs);
packed = ostree_wrap_metadata_variant (OSTREE_OBJECT_TYPE_DIR_META, dirmeta);
g_checksum_update (ret_checksum, g_variant_get_data (packed),
g_variant_get_size (packed));
g_checksum_update (ret_checksum, g_variant_get_data (dirmeta),
g_variant_get_size (dirmeta));
}
else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
@ -464,61 +473,6 @@ ostree_set_xattrs (GFile *f,
return ret;
}
gboolean
ostree_unwrap_metadata (GVariant *container,
OstreeObjectType expected_type,
GVariant **out_variant,
GError **error)
{
gboolean ret = FALSE;
guint32 actual_type;
ot_lvariant GVariant *ret_variant = NULL;
g_variant_get (container, "(uv)",
&actual_type, &ret_variant);
actual_type = GUINT32_FROM_BE (actual_type);
if (actual_type != expected_type)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Corrupted metadata object; found type %u, expected %u",
actual_type, (guint32)expected_type);
goto out;
}
ret = TRUE;
ot_transfer_out_value (out_variant, &ret_variant);
out:
return ret;
}
gboolean
ostree_map_metadata_file (GFile *file,
OstreeObjectType expected_type,
GVariant **out_variant,
GError **error)
{
gboolean ret = FALSE;
ot_lvariant GVariant *ret_variant = NULL;
ot_lvariant GVariant *container = NULL;
if (!ot_util_variant_map (file, OSTREE_SERIALIZED_VARIANT_FORMAT,
&container, error))
goto out;
if (!ostree_unwrap_metadata (container, expected_type, &ret_variant,
error))
{
g_prefix_error (error, "While parsing '%s': ",
ot_gfile_get_path_cached (file));
goto out;
}
ret = TRUE;
ot_transfer_out_value(out_variant, &ret_variant);
out:
return ret;
}
const char *
ostree_object_type_to_string (OstreeObjectType objtype)
{

View File

@ -43,8 +43,6 @@ typedef enum {
#define OSTREE_OBJECT_TYPE_IS_META(t) (t >= 3 && t <= 6)
#define OSTREE_OBJECT_TYPE_LAST OSTREE_OBJECT_TYPE_COMMIT
#define OSTREE_SERIALIZED_VARIANT_FORMAT G_VARIANT_TYPE("(uv)")
/*
* xattr objects:
* a(ayay) - array of (name, value) pairs, both binary data, though name is a bytestring
@ -132,6 +130,8 @@ typedef enum {
*/
#define OSTREE_PACK_META_FILE_VARIANT_FORMAT G_VARIANT_TYPE ("(yayv)")
const GVariantType *ostree_metadata_variant_type (OstreeObjectType objtype);
gboolean ostree_validate_checksum_string (const char *sha256,
GError **error);
@ -187,13 +187,6 @@ gboolean ostree_get_xattrs_for_file (GFile *f,
GCancellable *cancellable,
GError **error);
GVariant *ostree_wrap_metadata_variant (OstreeObjectType type, GVariant *metadata);
gboolean ostree_unwrap_metadata (GVariant *container,
OstreeObjectType expected_type,
GVariant **out_variant,
GError **error);
gboolean ostree_set_xattrs (GFile *f, GVariant *xattrs,
GCancellable *cancellable, GError **error);

View File

@ -288,35 +288,22 @@ ostree_repo_file_get_commit (OstreeRepoFile *self)
gboolean
ostree_repo_file_get_xattrs (OstreeRepoFile *self,
GVariant **out_xattrs,
GCancellable *cancellable,
GError **error)
GVariant **out_xattrs,
GCancellable *cancellable,
GError **error)
{
gboolean ret = FALSE;
ot_lvariant GVariant *ret_xattrs = NULL;
ot_lvariant GVariant *metadata = NULL;
ot_lobj GFile *local_file = NULL;
if (!ostree_repo_file_ensure_resolved (self, error))
goto out;
if (self->tree_metadata)
ret_xattrs = g_variant_get_child_value (self->tree_metadata, 3);
else if (ostree_repo_get_mode (self->repo) == OSTREE_REPO_MODE_ARCHIVE)
{
local_file = ostree_repo_file_nontree_get_local (self);
if (!ostree_map_metadata_file (local_file, OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META,
&metadata, error))
goto out;
if (!ostree_parse_archived_file_meta (metadata, NULL, &ret_xattrs, error))
goto out;
}
else
{
local_file = ostree_repo_file_nontree_get_local (self);
if (!ostree_get_xattrs_for_file (local_file, &ret_xattrs, cancellable, error))
if (!ostree_repo_load_file (self->repo, ostree_repo_file_get_checksum (self),
NULL, NULL, &ret_xattrs, cancellable, error))
goto out;
}

View File

@ -53,9 +53,9 @@ gboolean ostree_repo_file_ensure_resolved (OstreeRepoFile *self,
GError **error);
gboolean ostree_repo_file_get_xattrs (OstreeRepoFile *self,
GVariant **out_xattrs,
GCancellable *cancellable,
GError **error);
GVariant **out_xattrs,
GCancellable *cancellable,
GError **error);
OstreeRepo * ostree_repo_file_get_repo (OstreeRepoFile *self);
OstreeRepoFile * ostree_repo_file_get_root (OstreeRepoFile *self);

View File

@ -822,14 +822,12 @@ impl_stage_archive_file_object_from_raw (OstreeRepo *self,
ot_lobj GFile *meta_temp_file = NULL;
ot_lobj GFile *content_temp_file = NULL;
ot_lobj GInputStream *mem = NULL;
ot_lvariant GVariant *serialized = NULL;
GChecksum *ret_checksum = NULL;
archive_metadata = ostree_create_archive_file_metadata (file_info, xattrs);
serialized = ostree_wrap_metadata_variant (OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META, archive_metadata);
mem = g_memory_input_stream_new_from_data (g_variant_get_data (serialized),
g_variant_get_size (serialized),
mem = g_memory_input_stream_new_from_data (g_variant_get_data (archive_metadata),
g_variant_get_size (archive_metadata),
NULL);
if (!ostree_create_temp_file_from_input (priv->tmp_dir,
@ -1071,13 +1069,11 @@ stage_gvariant_object (OstreeRepo *self,
GError **error)
{
gboolean ret = FALSE;
ot_lvariant GVariant *serialized = NULL;
ot_lobj GInputStream *mem = NULL;
GChecksum *ret_checksum = NULL;
serialized = ostree_wrap_metadata_variant (type, variant);
mem = g_memory_input_stream_new_from_data (g_variant_get_data (serialized),
g_variant_get_size (serialized),
mem = g_memory_input_stream_new_from_data (g_variant_get_data (variant),
g_variant_get_size (variant),
NULL);
if (!stage_object_impl (self, type, FALSE,
@ -3510,7 +3506,8 @@ ostree_repo_load_variant (OstreeRepo *self,
/* Prefer loose metadata for now */
if (object_path != NULL)
{
if (!ostree_map_metadata_file (object_path, objtype, &ret_variant, error))
if (!ot_util_variant_map (object_path, ostree_metadata_variant_type (objtype),
&ret_variant, error))
goto out;
}
else if (pack_checksum != NULL)

View File

@ -655,7 +655,6 @@ fetch_and_store_file (OtPullData *pull_data,
ot_lobj GInputStream *input = NULL;
ot_lobj GFile *stored_path = NULL;
ot_lfree char *pack_checksum = NULL;
ot_lvariant GVariant *archive_metadata_container = NULL;
ot_lvariant GVariant *archive_metadata = NULL;
ot_lobj GFileInfo *archive_file_info = NULL;
ot_lvariant GVariant *archive_xattrs = NULL;
@ -686,12 +685,8 @@ fetch_and_store_file (OtPullData *pull_data,
if (input != NULL)
{
if (!ot_util_variant_from_stream (input, OSTREE_SERIALIZED_VARIANT_FORMAT,
FALSE, &archive_metadata_container, cancellable, error))
goto out;
if (!ostree_unwrap_metadata (archive_metadata_container, OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META,
&archive_metadata, error))
if (!ot_util_variant_from_stream (input, OSTREE_ARCHIVED_FILE_VARIANT_FORMAT,
FALSE, &archive_metadata, cancellable, error))
goto out;
if (!ostree_parse_archived_file_meta (archive_metadata, &archive_file_info,

View File

@ -175,7 +175,6 @@ fsck_reachable_objects_from_commits (OtFsckData *data,
ot_lobj GFileInfo *file_info = NULL;
ot_lvariant GVariant *xattrs = NULL;
ot_lvariant GVariant *metadata = NULL;
ot_lvariant GVariant *metadata_wrapped = NULL;
GChecksum *computed_checksum = NULL;
reachable_objects = ostree_traverse_new_reachable ();
@ -248,11 +247,8 @@ fsck_reachable_objects_from_commits (OtFsckData *data,
else
g_assert_not_reached ();
ot_clear_gvariant (&metadata_wrapped);
metadata_wrapped = ostree_wrap_metadata_variant (objtype, metadata);
input = g_memory_input_stream_new_from_data (g_variant_get_data (metadata_wrapped),
g_variant_get_size (metadata_wrapped),
input = g_memory_input_stream_new_from_data (g_variant_get_data (metadata),
g_variant_get_size (metadata),
NULL);
}
else if (objtype == OSTREE_OBJECT_TYPE_ARCHIVED_FILE_CONTENT)

View File

@ -238,7 +238,7 @@ delete_loose_object (OtRepackData *data,
/* This is gross - we need to specially clean up symbolic link object content */
if (objtype == OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META)
{
if (!ostree_map_metadata_file (object_path, objtype, &archive_meta, error))
if (!ot_util_variant_map (object_path, OSTREE_ARCHIVED_FILE_VARIANT_FORMAT, &archive_meta, error))
goto out;
if (!ostree_parse_archived_file_meta (archive_meta, &file_info, &xattrs, error))
goto out;
@ -283,7 +283,8 @@ pack_one_meta_object (OtRepackData *data,
object_path = ostree_repo_get_object_path (data->repo, checksum, objtype);
if (!ostree_map_metadata_file (object_path, objtype, &metadata_v, error))
if (!ot_util_variant_map (object_path, ostree_metadata_variant_type (objtype),
&metadata_v, error))
goto out;
ret_packed_object = g_variant_new ("(y@ayv)", (guchar) objtype,

View File

@ -101,7 +101,6 @@ unpack_one_object (OstreeRepo *repo,
ot_lobj GFileInfo *file_info = NULL;
ot_lvariant GVariant *xattrs = NULL;
ot_lvariant GVariant *meta = NULL;
ot_lvariant GVariant *serialized_meta = NULL;
g_assert (objtype != OSTREE_OBJECT_TYPE_RAW_FILE);
@ -126,10 +125,8 @@ unpack_one_object (OstreeRepo *repo,
if (!ostree_repo_load_variant (repo, objtype, checksum, &meta, error))
goto out;
serialized_meta = ostree_wrap_metadata_variant (objtype, meta);
input = g_memory_input_stream_new_from_data (g_variant_get_data (serialized_meta),
g_variant_get_size (serialized_meta), NULL);
input = g_memory_input_stream_new_from_data (g_variant_get_data (meta),
g_variant_get_size (meta), NULL);
if (!ostree_repo_stage_object_trusted (repo, objtype, checksum, TRUE,
NULL, NULL, input, cancellable, error))