From ce139ea5ccb00e05951c8893d7fe6552d6033ac1 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 8 Feb 2025 14:59:59 +0000 Subject: [PATCH] oci: Write the OCI layout file Signed-off-by: Michael Tremer --- src/pakfire/oci.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/pakfire/oci.c b/src/pakfire/oci.c index 2a63b7c4..18da4def 100644 --- a/src/pakfire/oci.c +++ b/src/pakfire/oci.c @@ -74,6 +74,34 @@ static const char* pakfire_oci_arch(struct pakfire* pakfire) { return arch; } +static int pakfire_oci_writer_write_oci_layout(struct pakfire_oci_writer* self) { + struct json_object* o = NULL; + int r; + + // Make a new object + o = pakfire_json_new_object(); + if (!o) { + r = -errno; + goto ERROR; + } + + // Set version + r = pakfire_json_add_string(o, "imageLayoutVersion", "1.0.0"); + if (r < 0) + goto ERROR; + + // Write the file + r = pakfire_archive_writer_create_file_from_json(self->image, "oci-layout", 0644, o); + if (r < 0) + goto ERROR; + +ERROR: + if (o) + json_object_put(o); + + return r; +} + static int pakfire_oci_writer_write_layer_version(struct pakfire_oci_writer* self) { char filename[PATH_MAX]; int r; @@ -267,6 +295,13 @@ int pakfire_oci_mkimage(struct pakfire* pakfire, FILE* f) { if (r < 0) goto ERROR; + // Write oci-layout file + r = pakfire_oci_writer_write_oci_layout(&writer); + if (r < 0) { + ERROR(writer.ctx, "Failed to write the OCI layout file: %s\n", strerror(-r)); + goto ERROR; + } + // Make the layer r = pakfire_oci_writer_make_layer(&writer); if (r < 0) -- 2.39.5