[ostree/wip/objtype] some tests pass
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree/wip/objtype] some tests pass
- Date: Tue, 13 Dec 2011 00:30:25 +0000 (UTC)
commit 170a00a8051ebb72c3916b07854d5d367f631b92
Author: Colin Walters <walters verbum org>
Date: Mon Dec 12 19:29:56 2011 -0500
some tests pass
src/libostree/ostree-core.c | 44 ++++++++++++++++++++++++++++---------
src/libostree/ostree-core.h | 2 +-
src/libostree/ostree-repo-file.c | 8 +++---
src/libostree/ostree-repo.c | 27 ++++++++--------------
src/ostree/ot-builtin-fsck.c | 2 +-
5 files changed, 49 insertions(+), 34 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index d373ee0..4b38c4e 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -445,34 +445,40 @@ ostree_set_xattrs (GFile *f,
gboolean
ostree_parse_metadata_file (GFile *file,
- OstreeObjectType *out_type,
+ OstreeObjectType expected_type,
GVariant **out_variant,
GError **error)
{
gboolean ret = FALSE;
GVariant *ret_variant = NULL;
GVariant *container = NULL;
- guint32 ret_type;
+ guint32 actual_type;
if (!ot_util_variant_map (file, G_VARIANT_TYPE (OSTREE_SERIALIZED_VARIANT_FORMAT),
&container, error))
goto out;
g_variant_get (container, "(uv)",
- &ret_type, &ret_variant);
- ret_type = GUINT32_FROM_BE (ret_type);
- if (!OSTREE_OBJECT_TYPE_IS_META (ret_type))
+ &actual_type, &ret_variant);
+ ot_util_variant_take_ref (ret_variant);
+ actual_type = GUINT32_FROM_BE (actual_type);
+ if (!OSTREE_OBJECT_TYPE_IS_META (actual_type))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Corrupted metadata object '%s'; invalid type %d",
- ot_gfile_get_path_cached (file), ret_type);
+ ot_gfile_get_path_cached (file), actual_type);
+ goto out;
+ }
+ 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",
+ ot_gfile_get_path_cached (file),
+ actual_type, (guint32)expected_type);
goto out;
}
- ot_util_variant_take_ref (ret_variant);
ret = TRUE;
- if (out_type)
- *out_type = ret_type;
ot_transfer_out_value(out_variant, &ret_variant);
out:
ot_clear_gvariant (&ret_variant);
@@ -528,6 +534,7 @@ ostree_create_archive_file_metadata (GFileInfo *finfo,
{
guint32 uid, gid, mode, rdev;
GVariantBuilder pack_builder;
+ GVariant *ret = NULL;
uid = g_file_info_get_attribute_uint32 (finfo, G_FILE_ATTRIBUTE_UNIX_UID);
gid = g_file_info_get_attribute_uint32 (finfo, G_FILE_ATTRIBUTE_UNIX_GID);
@@ -551,7 +558,10 @@ ostree_create_archive_file_metadata (GFileInfo *finfo,
g_variant_builder_add (&pack_builder, "s", content_checksum);
- return g_variant_builder_end (&pack_builder);
+ ret = g_variant_builder_end (&pack_builder);
+ g_variant_ref_sink (ret);
+
+ return ret;
}
gboolean
@@ -572,13 +582,25 @@ ostree_parse_archived_file_meta (GVariant *metadata,
g_variant_get (metadata, "(u a{sv}uuuu&s a(ayay)s)",
&version, &metametadata, &uid, &gid, &mode, &rdev,
&symlink_target, &ret_xattrs, &ret_content_checksum);
+ version = GUINT32_FROM_BE (version);
+
+ if (version != 0)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Invalid version %d in archived file metadata", version);
+ goto out;
+ }
+
uid = GUINT32_FROM_BE (uid);
gid = GUINT32_FROM_BE (gid);
mode = GUINT32_FROM_BE (mode);
rdev = GUINT32_FROM_BE (rdev);
if (!ostree_validate_checksum_string (ret_content_checksum, error))
- goto out;
+ {
+ g_prefix_error (error, "While parsing archived file metadata: ");
+ goto out;
+ }
ret_file_info = g_file_info_new ();
g_file_info_set_attribute_uint32 (ret_file_info, "standard::type", ot_gfile_type_for_mode (mode));
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h
index 708cb2d..08100e0 100644
--- a/src/libostree/ostree-core.h
+++ b/src/libostree/ostree-core.h
@@ -118,7 +118,7 @@ gboolean ostree_set_xattrs (GFile *f, GVariant *xattrs,
GCancellable *cancellable, GError **error);
gboolean ostree_parse_metadata_file (GFile *file,
- OstreeObjectType *out_type,
+ OstreeObjectType expected_type,
GVariant **out_variant,
GError **error);
diff --git a/src/libostree/ostree-repo-file.c b/src/libostree/ostree-repo-file.c
index bb5dcbf..d8e3b8f 100644
--- a/src/libostree/ostree-repo-file.c
+++ b/src/libostree/ostree-repo-file.c
@@ -319,8 +319,8 @@ _ostree_repo_file_get_xattrs (OstreeRepoFile *self,
{
local_file = _ostree_repo_file_nontree_get_local (self);
- if (!ot_util_variant_map (local_file, OSTREE_ARCHIVED_FILE_VARIANT_FORMAT,
- &metadata, error))
+ if (!ostree_parse_metadata_file (local_file, OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META,
+ &metadata, error))
goto out;
if (!ostree_parse_archived_file_meta (metadata, NULL, &ret_xattrs, NULL, error))
@@ -1038,8 +1038,8 @@ _ostree_repo_file_tree_query_child (OstreeRepoFile *self,
if (ostree_repo_get_mode (self->repo) == OSTREE_REPO_MODE_ARCHIVE)
{
- if (!ot_util_variant_map (local_child, OSTREE_ARCHIVED_FILE_VARIANT_FORMAT,
- &archive_metadata, error))
+ if (!ostree_parse_metadata_file (local_child, OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META,
+ &archive_metadata, error))
goto out;
if (!ostree_parse_archived_file_meta (archive_metadata, &ret_info, NULL, NULL, error))
goto out;
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 67f538d..4be3a35 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -37,7 +37,7 @@
#include "ostree-libarchive-input-stream.h"
#endif
-#define PENDING_TRANSACTION_OBJECT_GVARIANT_FORMAT (G_VARIANT_TYPE("(uss)"))
+#define PENDING_TRANSACTION_OBJECT_GVARIANT_FORMAT (G_VARIANT_TYPE("(us)"))
enum {
PROP_0,
@@ -802,6 +802,7 @@ impl_stage_raw_file_object_from_archive (OstreeRepo *self,
GVariant *archived_xattrs = NULL;
char *archived_content_checksum = NULL;
GVariant *archived_content = NULL; /* const */
+ guint32 pending_objtype;
const char *archived_content_path;
GFile *archived_content_file = NULL;
GInputStream *archived_content_input = NULL;
@@ -829,7 +830,8 @@ impl_stage_raw_file_object_from_archive (OstreeRepo *self,
goto out;
}
- g_variant_get (archived_content, "(u&s)", &archived_content_path);
+ g_variant_get (archived_content, "(u&s)", &pending_objtype, &archived_content_path);
+ g_assert (pending_objtype == OSTREE_OBJECT_TYPE_ARCHIVED_FILE_CONTENT);
archived_content_file = g_file_get_child (priv->tmp_dir, archived_content_path);
archived_content_input = (GInputStream*)g_file_read (archived_content_file, cancellable, error);
@@ -944,7 +946,7 @@ stage_object (OstreeRepo *self,
else
{
actual_checksum = g_checksum_get_string (ret_checksum);
- if (strcmp (actual_checksum, expected_checksum) != 0)
+ if (expected_checksum && strcmp (actual_checksum, expected_checksum) != 0)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Corrupted object %s (actual checksum is %s)",
@@ -1045,7 +1047,7 @@ ostree_repo_commit_transaction (OstreeRepo *self,
guint32 objtype;
const char *filename;
- g_variant_get (data, "(u&s&s)", &objtype, &filename, &checksum);
+ g_variant_get (data, "(u&s)", &objtype, &filename);
g_clear_object (&f);
f = g_file_get_child (priv->tmp_dir, filename);
@@ -1101,7 +1103,6 @@ ostree_repo_load_variant (OstreeRepo *self,
GError **error)
{
gboolean ret = FALSE;
- OstreeObjectType type;
GFile *object_path = NULL;
GVariant *ret_variant = NULL;
@@ -1109,17 +1110,9 @@ ostree_repo_load_variant (OstreeRepo *self,
object_path = ostree_repo_get_object_path (self, sha256, expected_type);
- if (!ostree_parse_metadata_file (object_path, &type, &ret_variant, error))
+ if (!ostree_parse_metadata_file (object_path, expected_type, &ret_variant, error))
goto out;
- if (type != expected_type)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Corrupted metadata object '%s'; found type %u, expected %u", sha256,
- type, (guint32)expected_type);
- goto out;
- }
-
ret = TRUE;
ot_transfer_out_value(out_variant, &ret_variant);
out:
@@ -1467,7 +1460,7 @@ stage_directory_recurse (OstreeRepo *self,
if (!xattrs)
goto out;
- if (!stage_object (self, get_objtype_for_repo_file (self),
+ if (!stage_object (self, OSTREE_OBJECT_TYPE_RAW_FILE,
child_info, xattrs, file_input, NULL,
&child_file_checksum, cancellable, error))
goto out;
@@ -1629,7 +1622,7 @@ import_libarchive_entry_file (OstreeRepo *self,
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
archive_stream = ostree_libarchive_input_stream_new (a);
- if (!stage_object (self, get_objtype_for_repo_file (self),
+ if (!stage_object (self, OSTREE_OBJECT_TYPE_RAW_FILE,
file_info, NULL, archive_stream,
NULL, &ret_checksum,
cancellable, error))
@@ -2299,7 +2292,7 @@ checkout_tree (OstreeRepo *self,
if (priv->mode == OSTREE_REPO_MODE_ARCHIVE)
{
- if (!ot_util_variant_map (object_path, OSTREE_ARCHIVED_FILE_VARIANT_FORMAT, &archive_metadata, error))
+ if (!ostree_parse_metadata_file (object_path, OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META, &archive_metadata, error))
goto out;
g_free (archive_content_checksum);
diff --git a/src/ostree/ot-builtin-fsck.c b/src/ostree/ot-builtin-fsck.c
index 229586c..0043ff5 100644
--- a/src/ostree/ot-builtin-fsck.c
+++ b/src/ostree/ot-builtin-fsck.c
@@ -59,7 +59,7 @@ checksum_archived_file (OtFsckData *data,
gsize bytes_read;
guint32 mode;
- if (!ot_util_variant_map (file, OSTREE_ARCHIVED_FILE_VARIANT_FORMAT, &archive_metadata, error))
+ if (!ostree_parse_metadata_file (file, OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META, &archive_metadata, error))
goto out;
if (!ostree_parse_archived_file_meta (archive_metadata, &file_info, &xattrs, &content_checksum, error))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]