Skip to content

Commit

Permalink
core: Add OSTREE_OBJECT_TYPE_COMMIT_META
Browse files Browse the repository at this point in the history
This is cleaner than the loose_path_with_suffix approach

Closes: #359
Approved by: cgwalters
  • Loading branch information
Mathnerd314 authored and rh-atomic-bot committed Jun 22, 2016
1 parent 55f5f73 commit 23049bb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 43 deletions.
7 changes: 0 additions & 7 deletions src/libostree/ostree-core-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
41 changes: 13 additions & 28 deletions src/libostree/ostree-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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" : "");
}

/**
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/libostree/ostree-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

/**
Expand All @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions src/libostree/ostree-repo-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
3 changes: 1 addition & 2 deletions src/libostree/ostree-repo-pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/libostree/ostree-repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 23049bb

Please sign in to comment.