[ostree/wip/packfile-rebase2] core: Refactor more bits into core
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree/wip/packfile-rebase2] core: Refactor more bits into core
- Date: Wed, 28 Mar 2012 00:49:02 +0000 (UTC)
commit 32b52d469b1bce87984dfdce18b46814bd154069
Author: Colin Walters <walters verbum org>
Date: Tue Mar 27 19:48:12 2012 -0400
core: Refactor more bits into core
src/libostree/ostree-core.c | 69 ++++++++++++++++++++++++++++++++++++++----
src/libostree/ostree-core.h | 21 +++++++++----
src/libostree/ostree-repo.c | 69 +++++++-----------------------------------
3 files changed, 88 insertions(+), 71 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index f2e5770..390cf2e 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -1212,13 +1212,13 @@ ostree_create_temp_hardlink (GFile *dir,
}
gboolean
-ostree_read_pack_entry (guchar *pack_data,
- guint64 pack_len,
- guint64 offset,
- gboolean trusted,
- GVariant **out_entry,
- GCancellable *cancellable,
- GError **error)
+ostree_read_pack_entry_raw (guchar *pack_data,
+ guint64 pack_len,
+ guint64 offset,
+ gboolean trusted,
+ GVariant **out_entry,
+ GCancellable *cancellable,
+ GError **error)
{
gboolean ret = FALSE;
GVariant *ret_entry = NULL;
@@ -1310,3 +1310,58 @@ ostree_read_pack_entry_as_stream (GVariant *pack_entry)
return ret_input;
}
+
+
+gboolean
+ostree_read_pack_entry_variant (GVariant *pack_entry,
+ OstreeObjectType expected_objtype,
+ gboolean trusted,
+ GVariant **out_variant,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ GInputStream *stream = NULL;
+ GMemoryOutputStream *data_stream = NULL;
+ GVariant *container_variant = NULL;
+ GVariant *ret_variant = NULL;
+ guint32 actual_type;
+
+ stream = ostree_read_pack_entry_as_stream (pack_entry);
+
+ data_stream = (GMemoryOutputStream*)g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
+
+ if (!g_output_stream_splice ((GOutputStream*)data_stream, stream,
+ G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
+ cancellable, error))
+ goto out;
+
+ container_variant = g_variant_new_from_data (OSTREE_SERIALIZED_VARIANT_FORMAT,
+ g_memory_output_stream_get_data (data_stream),
+ g_memory_output_stream_get_data_size (data_stream),
+ trusted, (GDestroyNotify) g_object_unref, data_stream);
+ data_stream = NULL; /* Transfer ownership */
+
+ g_variant_get (container_variant, "(uv)",
+ &actual_type, &ret_variant);
+ actual_type = GUINT32_FROM_BE (actual_type);
+
+ if (actual_type != expected_objtype)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Corrupted metadata object in pack file; found type %u, expected %u",
+ actual_type, (guint32)expected_objtype);
+ goto out;
+ }
+
+ ret = TRUE;
+ ot_transfer_out_value (out_variant, &ret_variant);
+ out:
+ g_clear_object (&stream);
+ g_clear_object (&data_stream);
+ ot_clear_gvariant (&ret_variant);
+ ot_clear_gvariant (&container_variant);
+ return ret;
+}
+
+
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h
index fde739c..7fedf81 100644
--- a/src/libostree/ostree-core.h
+++ b/src/libostree/ostree-core.h
@@ -265,14 +265,21 @@ gboolean ostree_parse_archived_file_meta (GVariant *data,
GVariant **out_xattrs,
GError **error);
-gboolean ostree_read_pack_entry (guchar *pack_data,
- guint64 pack_len,
- guint64 object_offset,
- gboolean trusted,
- GVariant **out_entry,
- GCancellable *cancellable,
- GError **error);
+gboolean ostree_read_pack_entry_raw (guchar *pack_data,
+ guint64 pack_len,
+ guint64 object_offset,
+ gboolean trusted,
+ GVariant **out_entry,
+ GCancellable *cancellable,
+ GError **error);
GInputStream *ostree_read_pack_entry_as_stream (GVariant *pack_entry);
+gboolean ostree_read_pack_entry_variant (GVariant *pack_entry,
+ OstreeObjectType expected_objtype,
+ gboolean trusted,
+ GVariant **out_variant,
+ GCancellable *cancellable,
+ GError **error);
+
#endif /* _OSTREE_REPO */
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 9672460..1d1f3be 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -2659,39 +2659,6 @@ bsearch_in_pack_index (GVariant *index_contents,
return FALSE;
}
-static gboolean
-get_pack_entry_as_variant (GVariant *pack_entry,
- const GVariantType *type,
- gboolean trusted,
- GVariant **out_variant,
- GCancellable *cancellable,
- GError **error)
-{
- gboolean ret = FALSE;
- GInputStream *stream;
- GMemoryOutputStream *data_stream;
- GVariant *ret_variant;
-
- stream = ostree_read_pack_entry_as_stream (pack_entry);
-
- data_stream = (GMemoryOutputStream*)g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
-
- if (!g_output_stream_splice ((GOutputStream*)data_stream, stream,
- G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
- cancellable, error))
- goto out;
-
- ret_variant = g_variant_new_from_data (type, g_memory_output_stream_get_data (data_stream),
- g_memory_output_stream_get_data_size (data_stream),
- trusted, (GDestroyNotify) g_object_unref, data_stream);
-
- ret = TRUE;
- g_variant_ref_sink (ret_variant);
- ot_transfer_out_value (out_variant, &ret_variant);
- out:
- return ret;
-}
-
gboolean
ostree_repo_load_file (OstreeRepo *self,
const char *checksum,
@@ -2756,9 +2723,9 @@ ostree_repo_load_file (OstreeRepo *self,
&content_pack_data, &content_pack_len,
cancellable, error))
goto out;
- if (!ostree_read_pack_entry (content_pack_data, content_pack_len,
- content_pack_offset, TRUE,
- &packed_object, cancellable, error))
+ if (!ostree_read_pack_entry_raw (content_pack_data, content_pack_len,
+ content_pack_offset, TRUE,
+ &packed_object, cancellable, error))
goto out;
ret_input = ostree_read_pack_entry_as_stream (packed_object);
}
@@ -3071,7 +3038,7 @@ out:
gboolean
ostree_repo_load_variant (OstreeRepo *self,
- OstreeObjectType expected_type,
+ OstreeObjectType objtype,
const char *sha256,
GVariant **out_variant,
GError **error)
@@ -3087,9 +3054,9 @@ ostree_repo_load_variant (OstreeRepo *self,
guint64 object_offset;
GCancellable *cancellable = NULL;
- g_return_val_if_fail (OSTREE_OBJECT_TYPE_IS_META (expected_type), FALSE);
+ g_return_val_if_fail (OSTREE_OBJECT_TYPE_IS_META (objtype), FALSE);
- if (!ostree_repo_find_object (self, expected_type, sha256, &object_path, NULL,
+ if (!ostree_repo_find_object (self, objtype, sha256, &object_path, NULL,
&pack_checksum, &object_offset,
cancellable, error))
goto out;
@@ -3097,7 +3064,7 @@ ostree_repo_load_variant (OstreeRepo *self,
/* Prefer loose metadata for now */
if (object_path != NULL)
{
- if (!ostree_map_metadata_file (object_path, expected_type, &ret_variant, error))
+ if (!ostree_map_metadata_file (object_path, objtype, &ret_variant, error))
goto out;
}
else if (pack_checksum != NULL)
@@ -3108,31 +3075,19 @@ ostree_repo_load_variant (OstreeRepo *self,
cancellable, error))
goto out;
- if (!ostree_read_pack_entry (pack_data, pack_len, object_offset,
- TRUE, &packed_object, cancellable, error))
+ if (!ostree_read_pack_entry_raw (pack_data, pack_len, object_offset,
+ TRUE, &packed_object, cancellable, error))
goto out;
- if (!get_pack_entry_as_variant (packed_object, OSTREE_SERIALIZED_VARIANT_FORMAT, TRUE,
- &container_variant, cancellable, error))
+ if (!ostree_read_pack_entry_variant (packed_object, objtype, TRUE,
+ &container_variant, cancellable, error))
goto out;
-
- g_variant_get (container_variant, "(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 '%s'; found type %u, expected %u",
- sha256, actual_type, (guint32)expected_type);
- goto out;
- }
}
else
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"No such metadata object %s.%s",
- sha256, ostree_object_type_to_string (expected_type));
+ sha256, ostree_object_type_to_string (objtype));
goto out;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]