mirror of
https://github.com/flatpak/flatpak.git
synced 2026-04-04 23:25:54 -04:00
oci: Add helpers to parse OCI delta index and manifest
This commit is contained in:
committed by
Alexander Larsson
parent
eaeb52b6a3
commit
3d8ca04565
@@ -135,6 +135,12 @@ const char * flatpak_oci_manifest_get_layer_digest (FlatpakOciManifest *s
|
||||
int i);
|
||||
GHashTable * flatpak_oci_manifest_get_annotations (FlatpakOciManifest *self);
|
||||
|
||||
/* Only useful for delta manifest */
|
||||
FlatpakOciDescriptor *flatpak_oci_manifest_find_delta_for (FlatpakOciManifest *deltamanifest,
|
||||
const char *from_diffid,
|
||||
const char *to_diffid);
|
||||
|
||||
|
||||
#define FLATPAK_TYPE_OCI_INDEX flatpak_oci_index_get_type ()
|
||||
G_DECLARE_FINAL_TYPE (FlatpakOciIndex, flatpak_oci_index, FLATPAK, OCI_INDEX, FlatpakOciVersioned)
|
||||
|
||||
@@ -162,6 +168,11 @@ FlatpakOciManifestDescriptor *flatpak_oci_index_get_manifest (FlatpakOciIndex *s
|
||||
FlatpakOciManifestDescriptor *flatpak_oci_index_get_only_manifest (FlatpakOciIndex *self);
|
||||
int flatpak_oci_index_get_n_manifests (FlatpakOciIndex *self);
|
||||
|
||||
/* Only useful for delta index */
|
||||
FlatpakOciDescriptor *flatpak_oci_index_find_delta_for (FlatpakOciIndex *delta_index,
|
||||
const char *for_digest);
|
||||
|
||||
|
||||
#define FLATPAK_TYPE_OCI_IMAGE flatpak_oci_image_get_type ()
|
||||
G_DECLARE_FINAL_TYPE (FlatpakOciImage, flatpak_oci_image, FLATPAK, OCI_IMAGE, FlatpakJson)
|
||||
|
||||
|
||||
@@ -375,6 +375,36 @@ flatpak_oci_manifest_get_annotations (FlatpakOciManifest *self)
|
||||
return self->annotations;
|
||||
}
|
||||
|
||||
FlatpakOciDescriptor *
|
||||
flatpak_oci_manifest_find_delta_for (FlatpakOciManifest *delta_manifest,
|
||||
const char *from_diffid,
|
||||
const char *to_diffid)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (from_diffid == NULL || to_diffid == NULL)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; delta_manifest->layers != NULL && delta_manifest->layers[i] != NULL; i++)
|
||||
{
|
||||
FlatpakOciDescriptor *layer = delta_manifest->layers[i];
|
||||
const char *layer_from = NULL, *layer_to = NULL;
|
||||
|
||||
if (layer->annotations != NULL)
|
||||
{
|
||||
layer_from = g_hash_table_lookup (layer->annotations, "io.github.containers.delta.from");
|
||||
layer_to = g_hash_table_lookup (layer->annotations, "io.github.containers.delta.to");
|
||||
|
||||
if (g_strcmp0 (layer_from, from_diffid) == 0 &&
|
||||
g_strcmp0 (layer_to, to_diffid) == 0)
|
||||
return layer;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
G_DEFINE_TYPE (FlatpakOciIndex, flatpak_oci_index, FLATPAK_TYPE_OCI_VERSIONED);
|
||||
|
||||
static void
|
||||
@@ -560,6 +590,31 @@ flatpak_oci_index_remove_manifest (FlatpakOciIndex *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
FlatpakOciDescriptor *
|
||||
flatpak_oci_index_find_delta_for (FlatpakOciIndex *delta_index,
|
||||
const char *for_digest)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (delta_index->manifests == NULL)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; delta_index->manifests[i] != NULL; i++)
|
||||
{
|
||||
FlatpakOciManifestDescriptor *d = delta_index->manifests[i];
|
||||
const char *target;
|
||||
|
||||
if (d->parent.annotations == NULL)
|
||||
continue;
|
||||
|
||||
target = g_hash_table_lookup (d->parent.annotations, "io.github.containers.delta.target");
|
||||
if (g_strcmp0 (target, for_digest) == 0)
|
||||
return &d->parent;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
G_DEFINE_TYPE (FlatpakOciImage, flatpak_oci_image, FLATPAK_TYPE_JSON);
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user