core: Add helper functions to convert (checksum, objtype) pair to/from string
This commit is contained in:
parent
277843f3a2
commit
70afd6011f
|
|
@ -564,6 +564,26 @@ ostree_object_type_from_string (const char *str)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
ostree_object_to_string (const char *checksum,
|
||||||
|
OstreeObjectType objtype)
|
||||||
|
{
|
||||||
|
return g_strconcat (checksum, ".", ostree_object_type_to_string (objtype), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ostree_object_from_string (const char *str,
|
||||||
|
gchar **out_checksum,
|
||||||
|
OstreeObjectType *out_objtype)
|
||||||
|
{
|
||||||
|
const char *dot;
|
||||||
|
|
||||||
|
dot = strrchr (str, '.');
|
||||||
|
g_assert (dot != NULL);
|
||||||
|
*out_checksum = g_strndup (str, dot - str);
|
||||||
|
*out_objtype = ostree_object_type_from_string (dot + 1);
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
ostree_get_relative_object_path (const char *checksum,
|
ostree_get_relative_object_path (const char *checksum,
|
||||||
OstreeObjectType type)
|
OstreeObjectType type)
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,13 @@ const char * ostree_object_type_to_string (OstreeObjectType objtype);
|
||||||
|
|
||||||
OstreeObjectType ostree_object_type_from_string (const char *str);
|
OstreeObjectType ostree_object_type_from_string (const char *str);
|
||||||
|
|
||||||
|
char * ostree_object_to_string (const char *checksum,
|
||||||
|
OstreeObjectType objtype);
|
||||||
|
|
||||||
|
void ostree_object_from_string (const char *str,
|
||||||
|
gchar **out_checksum,
|
||||||
|
OstreeObjectType *out_objtype);
|
||||||
|
|
||||||
char *ostree_get_relative_object_path (const char *checksum,
|
char *ostree_get_relative_object_path (const char *checksum,
|
||||||
OstreeObjectType type);
|
OstreeObjectType type);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -752,13 +752,6 @@ ostree_repo_get_file_object_path (OstreeRepo *self,
|
||||||
return ostree_repo_get_object_path (self, checksum, get_objtype_for_repo_file (self));
|
return ostree_repo_get_object_path (self, checksum, get_objtype_for_repo_file (self));
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
|
||||||
create_checksum_and_objtype (const char *checksum,
|
|
||||||
OstreeObjectType objtype)
|
|
||||||
{
|
|
||||||
return g_strconcat (checksum, ".", ostree_object_type_to_string (objtype), NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static GFile *
|
static GFile *
|
||||||
get_pending_object_path (OstreeRepo *self,
|
get_pending_object_path (OstreeRepo *self,
|
||||||
const char *checksum,
|
const char *checksum,
|
||||||
|
|
@ -847,7 +840,7 @@ insert_into_transaction (OstreeRepo *self,
|
||||||
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
||||||
char *key;
|
char *key;
|
||||||
|
|
||||||
key = create_checksum_and_objtype (checksum, objtype);
|
key = ostree_object_to_string (checksum, objtype);
|
||||||
/* Takes ownership */
|
/* Takes ownership */
|
||||||
g_hash_table_replace (priv->pending_transaction, key, NULL);
|
g_hash_table_replace (priv->pending_transaction, key, NULL);
|
||||||
}
|
}
|
||||||
|
|
@ -1165,22 +1158,15 @@ ostree_repo_commit_transaction (OstreeRepo *self,
|
||||||
GHashTableIter iter;
|
GHashTableIter iter;
|
||||||
gpointer key, value;
|
gpointer key, value;
|
||||||
char *checksum = NULL;
|
char *checksum = NULL;
|
||||||
|
OstreeObjectType objtype;
|
||||||
|
|
||||||
g_return_val_if_fail (priv->in_transaction == TRUE, FALSE);
|
g_return_val_if_fail (priv->in_transaction == TRUE, FALSE);
|
||||||
|
|
||||||
g_hash_table_iter_init (&iter, priv->pending_transaction);
|
g_hash_table_iter_init (&iter, priv->pending_transaction);
|
||||||
while (g_hash_table_iter_next (&iter, &key, &value))
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
||||||
{
|
{
|
||||||
const char *checksum_and_type = key;
|
|
||||||
const char *type_str;
|
|
||||||
OstreeObjectType objtype;
|
|
||||||
|
|
||||||
type_str = strrchr (checksum_and_type, '.');
|
|
||||||
g_assert (type_str);
|
|
||||||
g_free (checksum);
|
g_free (checksum);
|
||||||
checksum = g_strndup (checksum_and_type, type_str - checksum_and_type);
|
ostree_object_from_string ((char*)key, &checksum, &objtype);
|
||||||
|
|
||||||
objtype = ostree_object_type_from_string (type_str + 1);
|
|
||||||
|
|
||||||
g_clear_object (&f);
|
g_clear_object (&f);
|
||||||
f = get_pending_object_path (self, checksum, objtype);
|
f = get_pending_object_path (self, checksum, objtype);
|
||||||
|
|
|
||||||
|
|
@ -69,13 +69,6 @@ typedef struct {
|
||||||
guint n_unreachable;
|
guint n_unreachable;
|
||||||
} OtPruneData;
|
} OtPruneData;
|
||||||
|
|
||||||
static char *
|
|
||||||
create_checksum_and_objtype (const char *checksum,
|
|
||||||
OstreeObjectType objtype)
|
|
||||||
{
|
|
||||||
return g_strconcat (checksum, ".", ostree_object_type_to_string (objtype), NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
compute_reachable_objects_from_dir_contents (OstreeRepo *repo,
|
compute_reachable_objects_from_dir_contents (OstreeRepo *repo,
|
||||||
const char *sha256,
|
const char *sha256,
|
||||||
|
|
@ -93,7 +86,7 @@ compute_reachable_objects_from_dir_contents (OstreeRepo *repo,
|
||||||
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_TREE, sha256, &tree, error))
|
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_DIR_TREE, sha256, &tree, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
key = create_checksum_and_objtype (sha256, OSTREE_OBJECT_TYPE_DIR_TREE);
|
key = ostree_object_to_string (sha256, OSTREE_OBJECT_TYPE_DIR_TREE);
|
||||||
g_hash_table_replace (inout_reachable, key, key);
|
g_hash_table_replace (inout_reachable, key, key);
|
||||||
|
|
||||||
/* PARSE OSTREE_SERIALIZED_TREE_VARIANT */
|
/* PARSE OSTREE_SERIALIZED_TREE_VARIANT */
|
||||||
|
|
@ -107,14 +100,14 @@ compute_reachable_objects_from_dir_contents (OstreeRepo *repo,
|
||||||
g_variant_get_child (files_variant, i, "(&s&s)", &filename, &checksum);
|
g_variant_get_child (files_variant, i, "(&s&s)", &filename, &checksum);
|
||||||
if (ostree_repo_get_mode (repo) == OSTREE_REPO_MODE_BARE)
|
if (ostree_repo_get_mode (repo) == OSTREE_REPO_MODE_BARE)
|
||||||
{
|
{
|
||||||
key = create_checksum_and_objtype (checksum, OSTREE_OBJECT_TYPE_RAW_FILE);
|
key = ostree_object_to_string (checksum, OSTREE_OBJECT_TYPE_RAW_FILE);
|
||||||
g_hash_table_replace (inout_reachable, key, key);
|
g_hash_table_replace (inout_reachable, key, key);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
key = create_checksum_and_objtype (checksum, OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META);
|
key = ostree_object_to_string (checksum, OSTREE_OBJECT_TYPE_ARCHIVED_FILE_META);
|
||||||
g_hash_table_replace (inout_reachable, key, key);
|
g_hash_table_replace (inout_reachable, key, key);
|
||||||
key = create_checksum_and_objtype (checksum, OSTREE_OBJECT_TYPE_ARCHIVED_FILE_CONTENT);
|
key = ostree_object_to_string (checksum, OSTREE_OBJECT_TYPE_ARCHIVED_FILE_CONTENT);
|
||||||
g_hash_table_replace (inout_reachable, key, key);
|
g_hash_table_replace (inout_reachable, key, key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +127,7 @@ compute_reachable_objects_from_dir_contents (OstreeRepo *repo,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
key = create_checksum_and_objtype (meta_checksum, OSTREE_OBJECT_TYPE_DIR_META);
|
key = ostree_object_to_string (meta_checksum, OSTREE_OBJECT_TYPE_DIR_META);
|
||||||
g_hash_table_replace (inout_reachable, key, key);
|
g_hash_table_replace (inout_reachable, key, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,7 +159,7 @@ compute_reachable_objects_from_commit (OstreeRepo *repo,
|
||||||
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, sha256, &commit, error))
|
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, sha256, &commit, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
key = create_checksum_and_objtype (sha256, OSTREE_OBJECT_TYPE_COMMIT);
|
key = ostree_object_to_string (sha256, OSTREE_OBJECT_TYPE_COMMIT);
|
||||||
g_hash_table_replace (inout_reachable, key, key);
|
g_hash_table_replace (inout_reachable, key, key);
|
||||||
|
|
||||||
/* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */
|
/* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */
|
||||||
|
|
@ -184,7 +177,7 @@ compute_reachable_objects_from_commit (OstreeRepo *repo,
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
g_variant_get_child (commit, 7, "&s", &meta_checksum);
|
g_variant_get_child (commit, 7, "&s", &meta_checksum);
|
||||||
key = create_checksum_and_objtype (meta_checksum, OSTREE_OBJECT_TYPE_DIR_META);
|
key = ostree_object_to_string (meta_checksum, OSTREE_OBJECT_TYPE_DIR_META);
|
||||||
g_hash_table_replace (inout_reachable, key, key);
|
g_hash_table_replace (inout_reachable, key, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,7 +198,7 @@ object_iter_callback (OstreeRepo *repo,
|
||||||
OtPruneData *data = user_data;
|
OtPruneData *data = user_data;
|
||||||
char *key;
|
char *key;
|
||||||
|
|
||||||
key = create_checksum_and_objtype (checksum, objtype);
|
key = ostree_object_to_string (checksum, objtype);
|
||||||
|
|
||||||
if (!g_hash_table_lookup_extended (data->reachable, key, NULL, NULL))
|
if (!g_hash_table_lookup_extended (data->reachable, key, NULL, NULL))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue