From 23049bbd011924b1e34514b14e58d82519346d36 Mon Sep 17 00:00:00 2001 From: Mathnerd314 Date: Wed, 15 Jun 2016 23:37:29 -0600 Subject: [PATCH] core: Add OSTREE_OBJECT_TYPE_COMMIT_META This is cleaner than the loose_path_with_suffix approach Closes: #359 Approved by: cgwalters --- src/libostree/ostree-core-private.h | 7 ----- src/libostree/ostree-core.c | 41 +++++++++-------------------- src/libostree/ostree-core.h | 6 +++-- src/libostree/ostree-repo-commit.c | 3 +-- src/libostree/ostree-repo-pull.c | 3 +-- src/libostree/ostree-repo.c | 3 +-- 6 files changed, 20 insertions(+), 43 deletions(-) diff --git a/src/libostree/ostree-core-private.h b/src/libostree/ostree-core-private.h index 91d52f1b..b49e5e47 100644 --- a/src/libostree/ostree-core-private.h +++ b/src/libostree/ostree-core-private.h @@ -128,13 +128,6 @@ _ostree_loose_path (char *buf, OstreeObjectType objtype, OstreeRepoMode repo_mode); -void -_ostree_loose_path_with_suffix (char *buf, - const char *checksum, - OstreeObjectType objtype, - OstreeRepoMode repo_mode, - const char *suffix); - #define _OSTREE_METADATA_GPGSIGS_NAME "ostree.gpgsigs" #define _OSTREE_METADATA_GPGSIGS_TYPE G_VARIANT_TYPE ("aay") diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c index 4e3816f5..32f0fd44 100644 --- a/src/libostree/ostree-core.c +++ b/src/libostree/ostree-core.c @@ -1047,6 +1047,8 @@ ostree_object_type_to_string (OstreeObjectType objtype) return "commit"; case OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT: return "tombstone-commit"; + case OSTREE_OBJECT_TYPE_COMMIT_META: + return "commitmeta"; default: g_assert_not_reached (); return NULL; @@ -1070,6 +1072,10 @@ ostree_object_type_from_string (const char *str) return OSTREE_OBJECT_TYPE_DIR_META; else if (!strcmp (str, "commit")) return OSTREE_OBJECT_TYPE_COMMIT; + else if (!strcmp (str, "tombstone-commit")) + return OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT; + else if (!strcmp (str, "commitmeta")) + return OSTREE_OBJECT_TYPE_COMMIT_META; g_assert_not_reached (); return 0; } @@ -1414,7 +1420,13 @@ _ostree_loose_path (char *buf, OstreeObjectType objtype, OstreeRepoMode mode) { - _ostree_loose_path_with_suffix (buf, checksum, objtype, mode, ""); + *buf = checksum[0]; + buf++; + *buf = checksum[1]; + buf++; + snprintf (buf, _OSTREE_LOOSE_PATH_MAX - 2, "/%s.%s%s", + checksum + 2, ostree_object_type_to_string (objtype), + (!OSTREE_OBJECT_TYPE_IS_META (objtype) && mode == OSTREE_REPO_MODE_ARCHIVE_Z2) ? "z" : ""); } /** @@ -1442,33 +1454,6 @@ _ostree_header_gfile_info_new (mode_t mode, uid_t uid, gid_t gid) return ret; } -/* - * _ostree_loose_path_with_suffix: - * @buf: Output buffer, must be _OSTREE_LOOSE_PATH_MAX in size - * @checksum: ASCII checksum - * @objtype: Object type - * @mode: Repository mode - * - * Like _ostree_loose_path, but also append a further arbitrary - * suffix; useful for finding non-core objects. - */ -void -_ostree_loose_path_with_suffix (char *buf, - const char *checksum, - OstreeObjectType objtype, - OstreeRepoMode mode, - const char *suffix) -{ - *buf = checksum[0]; - buf++; - *buf = checksum[1]; - buf++; - snprintf (buf, _OSTREE_LOOSE_PATH_MAX - 2, "/%s.%s%s%s", - checksum + 2, ostree_object_type_to_string (objtype), - (!OSTREE_OBJECT_TYPE_IS_META (objtype) && mode == OSTREE_REPO_MODE_ARCHIVE_Z2) ? "z" : "", - suffix); -} - /* * _ostree_get_relative_object_path: * @checksum: ASCII checksum string diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h index b8675672..415369d5 100644 --- a/src/libostree/ostree-core.h +++ b/src/libostree/ostree-core.h @@ -72,6 +72,7 @@ G_BEGIN_DECLS * @OSTREE_OBJECT_TYPE_DIR_META: Directory metadata * @OSTREE_OBJECT_TYPE_COMMIT: Toplevel object, refers to tree and dirmeta for root * @OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT: Toplevel object, refers to a deleted commit + * @OSTREE_OBJECT_TYPE_COMMIT_META: Detached metadata for a commit * * Enumeration for core object types; %OSTREE_OBJECT_TYPE_FILE is for * content, the other types are metadata. @@ -82,6 +83,7 @@ typedef enum { OSTREE_OBJECT_TYPE_DIR_META = 3, /* .dirmeta */ OSTREE_OBJECT_TYPE_COMMIT = 4, /* .commit */ OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT = 5, /* .commit-tombstone */ + OSTREE_OBJECT_TYPE_COMMIT_META = 6, /* .commitmeta */ } OstreeObjectType; /** @@ -90,14 +92,14 @@ typedef enum { * * Returns: %TRUE if object type is metadata */ -#define OSTREE_OBJECT_TYPE_IS_META(t) (t >= 2 && t <= 5) +#define OSTREE_OBJECT_TYPE_IS_META(t) (t >= 2 && t <= 6) /** * OSTREE_OBJECT_TYPE_LAST: * * Last valid object type; use this to validate ranges. */ -#define OSTREE_OBJECT_TYPE_LAST OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT +#define OSTREE_OBJECT_TYPE_LAST OSTREE_OBJECT_TYPE_COMMIT_META /** * OSTREE_DIRMETA_GVARIANT_FORMAT: diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 3670dea7..662ee21e 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -2058,8 +2058,7 @@ _ostree_repo_get_commit_metadata_loose_path (OstreeRepo *self, const char *checksum) { char buf[_OSTREE_LOOSE_PATH_MAX]; - _ostree_loose_path_with_suffix (buf, checksum, OSTREE_OBJECT_TYPE_COMMIT, self->mode, - "meta"); + _ostree_loose_path (buf, checksum, OSTREE_OBJECT_TYPE_COMMIT_META, self->mode); return g_file_resolve_relative_path (self->objects_dir, buf); } diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index 672da831..b4a565e3 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -1316,8 +1316,7 @@ enqueue_one_object_request (OtPullData *pull_data, if (is_detached_meta) { char buf[_OSTREE_LOOSE_PATH_MAX]; - _ostree_loose_path_with_suffix (buf, checksum, OSTREE_OBJECT_TYPE_COMMIT, - pull_data->remote_mode, "meta"); + _ostree_loose_path (buf, checksum, OSTREE_OBJECT_TYPE_COMMIT_META, pull_data->remote_mode); obj_uri = suburi_new (pull_data->base_uri, "objects", buf, NULL); } else diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c index c6520a80..e30b48cf 100644 --- a/src/libostree/ostree-repo.c +++ b/src/libostree/ostree-repo.c @@ -3120,8 +3120,7 @@ ostree_repo_delete_object (OstreeRepo *self, { char meta_loose[_OSTREE_LOOSE_PATH_MAX]; - _ostree_loose_path_with_suffix (meta_loose, sha256, - OSTREE_OBJECT_TYPE_COMMIT, self->mode, "meta"); + _ostree_loose_path (meta_loose, sha256, OSTREE_OBJECT_TYPE_COMMIT_META, self->mode); do res = unlinkat (self->objects_dir_fd, meta_loose, 0);