[ostree: 2/4] core: Add utility functions to convert a OstreeObjectType to/from a string
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree: 2/4] core: Add utility functions to convert a OstreeObjectType to/from a string
- Date: Thu, 15 Dec 2011 18:44:56 +0000 (UTC)
commit 8ab2296a70d95a9a1fe4ca276d417e63779366d0
Author: Colin Walters <walters verbum org>
Date: Thu Dec 15 13:09:51 2011 -0500
core: Add utility functions to convert a OstreeObjectType to/from a string
src/libostree/ostree-core.c | 67 +++++++++++++++++++++++++++++--------------
src/libostree/ostree-core.h | 15 +++++++++
2 files changed, 60 insertions(+), 22 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index b9e9347..c70ca70 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -480,12 +480,53 @@ ostree_parse_metadata_file (GFile *file,
return ret;
}
+const char *
+ostree_object_type_to_string (OstreeObjectType objtype)
+{
+ switch (objtype)
+ {
+ case OSTREE_OBJECT_TYPE_RAW_FILE:
+ return "file";
+ case OSTREE_OBJECT_TYPE_ARCHIVED_FILE_CONTENT:
+ return "archive-content";
+ case OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META:
+ return "archive-meta";
+ case OSTREE_OBJECT_TYPE_DIR_TREE:
+ return "dirtree";
+ case OSTREE_OBJECT_TYPE_DIR_META:
+ return "dirmeta";
+ case OSTREE_OBJECT_TYPE_COMMIT:
+ return "commit";
+ default:
+ g_assert_not_reached ();
+ return NULL;
+ }
+}
+
+OstreeObjectType
+ostree_object_type_from_string (const char *str)
+{
+ if (!strcmp (str, "file"))
+ return OSTREE_OBJECT_TYPE_RAW_FILE;
+ else if (!strcmp (str, "archive-content"))
+ return OSTREE_OBJECT_TYPE_ARCHIVED_FILE_CONTENT;
+ else if (!strcmp (str, "archive-meta"))
+ return OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META;
+ else if (!strcmp (str, "dirtree"))
+ return OSTREE_OBJECT_TYPE_DIR_TREE;
+ else if (!strcmp (str, "dirmeta"))
+ return OSTREE_OBJECT_TYPE_DIR_META;
+ else if (!strcmp (str, "commit"))
+ return OSTREE_OBJECT_TYPE_COMMIT;
+ g_assert_not_reached ();
+ return 0;
+}
+
char *
ostree_get_relative_object_path (const char *checksum,
OstreeObjectType type)
{
GString *path;
- const char *type_string;
g_assert (strlen (checksum) == 64);
@@ -494,27 +535,9 @@ ostree_get_relative_object_path (const char *checksum,
g_string_append_len (path, checksum, 2);
g_string_append_c (path, '/');
g_string_append (path, checksum + 2);
- switch (type)
- {
- case OSTREE_OBJECT_TYPE_RAW_FILE:
- type_string = ".file";
- break;
- case OSTREE_OBJECT_TYPE_ARCHIVED_FILE:
- type_string = ".archive";
- break;
- case OSTREE_OBJECT_TYPE_DIR_TREE:
- type_string = ".dirtree";
- break;
- case OSTREE_OBJECT_TYPE_DIR_META:
- type_string = ".dirmeta";
- break;
- case OSTREE_OBJECT_TYPE_COMMIT:
- type_string = ".commit";
- break;
- default:
- g_assert_not_reached ();
- }
- g_string_append (path, type_string);
+ g_string_append_c (path, '.');
+ g_string_append (path, ostree_object_type_to_string (type));
+
return g_string_free (path, FALSE);
}
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h
index e18adbb..88513b2 100644
--- a/src/libostree/ostree-core.h
+++ b/src/libostree/ostree-core.h
@@ -85,11 +85,26 @@ typedef enum {
*/
#define OSTREE_COMMIT_GVARIANT_FORMAT "(ua{sv}ssstss)"
+/* Archive file objects:
+ * u - Version
+ * u - uid
+ * u - gid
+ * u - mode
+ * u - rdev
+ * s - symlink target
+ * a(ayay) - xattrs
+ */
+#define OSTREE_ARCHIVED_FILE_VARIANT_FORMAT G_VARIANT_TYPE ("(uuuuusa(ayay))")
+
gboolean ostree_validate_checksum_string (const char *sha256,
GError **error);
void ostree_checksum_update_stat (GChecksum *checksum, guint32 uid, guint32 gid, guint32 mode);
+const char * ostree_object_type_to_string (OstreeObjectType objtype);
+
+OstreeObjectType ostree_object_type_from_string (const char *str);
+
char *ostree_get_relative_object_path (const char *checksum,
OstreeObjectType type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]