[ostree] Switch to big-endian storage for all variant data
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] Switch to big-endian storage for all variant data
- Date: Tue, 1 Nov 2011 02:43:00 +0000 (UTC)
commit 8769f4afd8a70a4899765b9681ea0cd7ba4bc1a7
Author: Colin Walters <walters verbum org>
Date: Mon Oct 31 22:41:50 2011 -0400
Switch to big-endian storage for all variant data
This ensures the saved archives are architecture-independent.
src/libostree/ostree-core.c | 1 +
src/libostree/ostree-repo.c | 19 ++++++++++++-------
src/ot-builtin-log.c | 2 ++
3 files changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index ce54fbc..4befb01 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -356,6 +356,7 @@ ostree_parse_metadata_file (const char *path,
mfile);
g_variant_get (container, "(uv)",
&ret_type, &ret_variant);
+ ret_type = GUINT32_FROM_BE (ret_type);
if (ret_type <= 0 || ret_type > OSTREE_SERIALIZED_VARIANT_LAST)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index a1323c6..721f62b 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -518,7 +518,7 @@ import_gvariant_object (OstreeRepo *self,
int fd = -1;
GUnixOutputStream *stream = NULL;
- serialized = g_variant_new ("(uv)", (guint32)type, variant);
+ serialized = g_variant_new ("(uv)", GUINT32_TO_BE ((guint32)type), variant);
tmp_name = g_build_filename (priv->objects_path, "variant-tmp-XXXXXX", NULL);
fd = g_mkstemp (tmp_name);
@@ -639,9 +639,9 @@ import_directory_meta (OstreeRepo *self,
dirmeta = g_variant_new ("(uuuu a(ayay))",
OSTREE_DIR_META_VERSION,
- (guint32)stbuf.st_uid,
- (guint32)stbuf.st_gid,
- (guint32)(stbuf.st_mode & (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)),
+ GUINT32_TO_BE ((guint32)stbuf.st_uid),
+ GUINT32_TO_BE ((guint32)stbuf.st_gid),
+ GUINT32_TO_BE ((guint32)stbuf.st_mode),
xattrs);
xattrs = NULL; /* was floating */
g_variant_ref_sink (dirmeta);
@@ -1203,6 +1203,7 @@ parse_tree (OstreeRepo *self,
/* PARSE OSTREE_SERIALIZED_TREE_VARIANT */
g_variant_get (tree_variant, "(u a{sv}@a(ss)@a(sss))",
&version, &meta_variant, &files_variant, &dirs_variant);
+ version = GUINT32_FROM_BE (version);
ret_pdata = parsed_tree_data_new ();
n = g_variant_n_children (files_variant);
@@ -1366,7 +1367,7 @@ import_parsed_tree (OstreeRepo *self,
}
serialized_tree = g_variant_new ("(u a{sv}@a(ss)@a(sss))",
- 0,
+ GUINT32_TO_BE (0),
create_empty_gvariant_dict (),
g_variant_builder_end (&files_builder),
g_variant_builder_end (&dirs_builder));
@@ -1766,11 +1767,11 @@ commit_parsed_tree (OstreeRepo *self,
now = g_date_time_new_now_utc ();
commit = g_variant_new ("(u a{sv}ssstss)",
- OSTREE_COMMIT_VERSION,
+ GUINT32_TO_BE (OSTREE_COMMIT_VERSION),
create_empty_gvariant_dict (),
parent ? parent : "",
subject, body ? body : "",
- g_date_time_to_unix (now) / G_TIME_SPAN_SECOND,
+ GUINT64_TO_BE (g_date_time_to_unix (now)),
g_checksum_get_string (root_checksum),
root->metadata_sha256);
if (!import_gvariant_object (self, OSTREE_SERIALIZED_COMMIT_VARIANT,
@@ -2168,6 +2169,10 @@ checkout_one_directory (OstreeRepo *self,
g_variant_get (dir->meta_data, "(uuuu a(ayay))",
&version, &uid, &gid, &mode,
&xattr_variant);
+ version = GUINT32_FROM_BE (version);
+ uid = GUINT32_FROM_BE (uid);
+ gid = GUINT32_FROM_BE (gid);
+ mode = GUINT32_FROM_BE (mode);
if (mkdir (dest_path, (mode_t)mode) < 0)
{
diff --git a/src/ot-builtin-log.c b/src/ot-builtin-log.c
index 11ca664..a53d14b 100644
--- a/src/ot-builtin-log.c
+++ b/src/ot-builtin-log.c
@@ -101,6 +101,8 @@ ostree_builtin_log (int argc, char **argv, const char *prefix, GError **error)
g_variant_get (commit, "(u a{sv}&s&s&st&s&s)",
&version, &commit_metadata, &parent, &subject, &body,
×tamp, &contents, &root_metadata);
+ version = GUINT32_FROM_BE (version);
+ timestamp = GUINT64_FROM_BE (timestamp);
time_obj = g_date_time_new_from_unix_utc (timestamp);
formatted_date = g_date_time_format (time_obj, "%a %b %d %H:%M:%S %Y %z");
g_date_time_unref (time_obj);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]