]> git.ipfire.org Git - pakfire.git/commitdiff
oci: Write the OCI layout file
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 8 Feb 2025 14:59:59 +0000 (14:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 8 Feb 2025 14:59:59 +0000 (14:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/oci.c

index 2a63b7c4cc8f6f111e419d37806bc25f8976a9f4..18da4def91a521e77e999bcdcaf5a16c542f4af2 100644 (file)
@@ -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)