]> git.ipfire.org Git - pakfire.git/commitdiff
scriptlet: Create its own type
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 15:07:26 +0000 (15:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 15:07:26 +0000 (15:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/archive.c
src/pakfire/archive.h
src/pakfire/build.c
src/pakfire/db.c
src/pakfire/db.h
src/pakfire/packager.c
src/pakfire/packager.h
src/pakfire/scriptlet.c
src/pakfire/scriptlet.h
src/pakfire/transaction.c

index 6f556f6ae0fc0861ebe02c709f3546d600496e12..e6ae67865da27e59aa8eca202e07146e37ab8882 100644 (file)
@@ -83,7 +83,7 @@ struct pakfire_archive {
        pakfire_filelist* filelist;
 
        // Scriptlets
-       struct pakfire_scriptlet* scriptlets[MAX_SCRIPTLETS];
+       pakfire_scriptlet* scriptlets[MAX_SCRIPTLETS];
        unsigned int num_scriptlets;
 
        // Hashes
@@ -523,7 +523,7 @@ static int pakfire_archive_parse_format(pakfire_archive* archive,
 
 static int pakfire_archive_parse_scriptlet(pakfire_archive* archive,
                const char* path, const char* data, const size_t length) {
-       struct pakfire_scriptlet* scriptlet = NULL;
+       pakfire_scriptlet* scriptlet = NULL;
        const char* type = NULL;
        int r;
 
@@ -1892,9 +1892,9 @@ int pakfire_archive_make_package(pakfire_archive* archive,
        return r;
 }
 
-struct pakfire_scriptlet* pakfire_archive_get_scriptlet(
+pakfire_scriptlet* pakfire_archive_get_scriptlet(
                pakfire_archive* archive, const char* type) {
-       struct pakfire_scriptlet* scriptlet = NULL;
+       pakfire_scriptlet* scriptlet = NULL;
 
        for (unsigned int i = 0; i < archive->num_scriptlets; i++) {
                scriptlet = archive->scriptlets[i];
index 52364627110d5dea0c775855f30fa48d0df05f6e..17decc218083abcbffab432c1c9ccf59b732a0dd 100644 (file)
@@ -99,7 +99,7 @@ int pakfire_archive_unlink(pakfire_archive* archive);
 int pakfire_archive_copy(pakfire_archive* archive, const char* path);
 int pakfire_archive_link_or_copy(pakfire_archive* archive, const char* path);
 
-struct pakfire_scriptlet* pakfire_archive_get_scriptlet(
+pakfire_scriptlet* pakfire_archive_get_scriptlet(
        pakfire_archive* archive, const char* type);
 
 int pakfire_archive_apply_systemd_sysusers(pakfire_archive* archive);
index 7b8f55dc11dc01d432cfb1f4b08b0cc662e6b50d..0228f3b6d057664f3bfe57f9006b47daf7fc2647 100644 (file)
@@ -1111,7 +1111,7 @@ static int pakfire_build_process_scriptlet_dep(pakfire_ctx* ctx, void* data,
 }
 
 static int pakfire_build_add_scriptlet_requires(pakfire_build* build,
-               pakfire_package* pkg, struct pakfire_scriptlet* scriptlet) {
+               pakfire_package* pkg, pakfire_scriptlet* scriptlet) {
        struct pakfire_input_buffer buffer = {};
        int r;
 
@@ -1142,7 +1142,7 @@ static int pakfire_build_add_scriptlet_requires(pakfire_build* build,
 static int pakfire_build_package_add_scriptlet(pakfire_build* build,
                pakfire_package* pkg, pakfire_packager* packager,
                const char* type, const char* data) {
-       struct pakfire_scriptlet* scriptlet = NULL;
+       pakfire_scriptlet* scriptlet = NULL;
        char* shell = NULL;
        int r;
 
index 387ea74eb2fd1d946ef0852d1479514fe8ee9c7a..361e4255e328ae2410f3df881046ecf393d4722d 100644 (file)
@@ -1290,7 +1290,7 @@ static int pakfire_db_add_scriptlets(pakfire_db* db, unsigned long id, pakfire_a
 
        for (const char** type = pakfire_scriptlet_types; *type; type++) {
                // Fetch the scriptlet
-               struct pakfire_scriptlet* scriptlet = pakfire_archive_get_scriptlet(archive, *type);
+               pakfire_scriptlet* scriptlet = pakfire_archive_get_scriptlet(archive, *type);
                if (!scriptlet)
                        continue;
 
@@ -1764,9 +1764,9 @@ ERROR:
        return r;
 }
 
-struct pakfire_scriptlet* pakfire_db_get_scriptlet(pakfire_db* db,
+pakfire_scriptlet* pakfire_db_get_scriptlet(pakfire_db* db,
                pakfire_package* pkg, const char* type) {
-       struct pakfire_scriptlet* scriptlet = NULL;
+       pakfire_scriptlet* scriptlet = NULL;
        sqlite3_stmt* stmt = NULL;
        int r = 1;
 
index f3069b8717cb14bf56f7c287845d8450ad71cd47..0c1de8a06c7fbe8fdbb500f20f4eca6ebaff4d79 100644 (file)
@@ -51,7 +51,7 @@ int pakfire_db_remove_package(pakfire_db* db, pakfire_package* pkg);
 
 int pakfire_db_load(pakfire_db* db, pakfire_repo* repo);
 
-struct pakfire_scriptlet* pakfire_db_get_scriptlet(
+pakfire_scriptlet* pakfire_db_get_scriptlet(
        pakfire_db* db, pakfire_package* pkg, const char* type);
 
 int pakfire_db_filelist(pakfire_db* db, pakfire_filelist** filelist);
index f776587299edeb69022c28a354842d3f73cae9f2..5fe962fc0a231a44d76af565a73eac6234fbf3ec 100644 (file)
@@ -62,7 +62,7 @@ struct pakfire_packager {
        pakfire_filelist* filelist;
 
        // Scriptlets
-       struct pakfire_scriptlet** scriptlets;
+       pakfire_scriptlet** scriptlets;
        unsigned int num_scriptlets;
 
        // Digests
@@ -271,7 +271,7 @@ ERROR:
 }
 
 static int pakfire_packager_write_scriptlet(pakfire_packager* packager,
-               pakfire_archive_writer* writer, struct pakfire_scriptlet* scriptlet) {
+               pakfire_archive_writer* writer, pakfire_scriptlet* scriptlet) {
        char filename[PATH_MAX];
        size_t size;
        int r;
@@ -550,7 +550,7 @@ int pakfire_packager_add_files(
 }
 
 int pakfire_packager_add_scriptlet(pakfire_packager* packager,
-               struct pakfire_scriptlet* scriptlet) {
+               pakfire_scriptlet* scriptlet) {
        if (!scriptlet)
                return -EINVAL;
 
index 83d4b7bab853f5aa705e141ea62f4030ce0d894f..49a51ac29215332b1447f148e8da9fdada6a8a92 100644 (file)
@@ -50,7 +50,7 @@ int pakfire_packager_add(pakfire_packager* packager,
        const char* sourcepath, const char* path);
 
 int pakfire_packager_add_scriptlet(pakfire_packager* packager,
-       struct pakfire_scriptlet* scriptlet);
+       pakfire_scriptlet* scriptlet);
 
 int pakfire_packager_cleanup(pakfire_packager* packager);
 
index eae5e7ac09295e1932e68a6622c8d01d84b0ee06..bc6458f0199fb8e13dfb63f25c25d2b9b6522110 100644 (file)
@@ -67,7 +67,7 @@ static int pakfire_scriptlet_valid_type(const char* type) {
        return 0;
 }
 
-static int pakfire_scriptlet_set(struct pakfire_scriptlet* scriptlet, const char* data, size_t size) {
+static int pakfire_scriptlet_set(pakfire_scriptlet* scriptlet, const char* data, size_t size) {
        if (scriptlet->data)
                free(scriptlet->data);
 
@@ -87,7 +87,7 @@ static int pakfire_scriptlet_set(struct pakfire_scriptlet* scriptlet, const char
        return 0;
 }
 
-static void pakfire_scriptlet_free(struct pakfire_scriptlet* scriptlet) {
+static void pakfire_scriptlet_free(pakfire_scriptlet* scriptlet) {
        if (scriptlet->data)
                free(scriptlet->data);
        if (scriptlet->ctx)
@@ -95,7 +95,7 @@ static void pakfire_scriptlet_free(struct pakfire_scriptlet* scriptlet) {
        free(scriptlet);
 }
 
-int pakfire_scriptlet_create(struct pakfire_scriptlet** scriptlet,
+int pakfire_scriptlet_create(pakfire_scriptlet** scriptlet,
                pakfire_ctx* ctx, const char* type, const char* data, size_t size) {
        int r;
 
@@ -108,7 +108,7 @@ int pakfire_scriptlet_create(struct pakfire_scriptlet** scriptlet,
                return -ENOTSUP;
 
        // Allocate some memory
-       struct pakfire_scriptlet* s = calloc(1, sizeof(*s));
+       pakfire_scriptlet* s = calloc(1, sizeof(*s));
        if (!s)
                return -errno;
 
@@ -139,13 +139,13 @@ ERROR:
        return r;
 };
 
-struct pakfire_scriptlet* pakfire_scriptlet_ref(struct pakfire_scriptlet* scriptlet) {
+pakfire_scriptlet* pakfire_scriptlet_ref(pakfire_scriptlet* scriptlet) {
        scriptlet->nrefs++;
 
        return scriptlet;
 }
 
-struct pakfire_scriptlet* pakfire_scriptlet_unref(struct pakfire_scriptlet* scriptlet) {
+pakfire_scriptlet* pakfire_scriptlet_unref(pakfire_scriptlet* scriptlet) {
        if (--scriptlet->nrefs > 0)
                return scriptlet;
 
@@ -153,18 +153,18 @@ struct pakfire_scriptlet* pakfire_scriptlet_unref(struct pakfire_scriptlet* scri
        return NULL;
 }
 
-const char* pakfire_scriptlet_get_type(struct pakfire_scriptlet* scriptlet) {
+const char* pakfire_scriptlet_get_type(pakfire_scriptlet* scriptlet) {
        return scriptlet->type;
 }
 
-const char* pakfire_scriptlet_get_data(struct pakfire_scriptlet* scriptlet, size_t* size) {
+const char* pakfire_scriptlet_get_data(pakfire_scriptlet* scriptlet, size_t* size) {
        if (size)
                *size = scriptlet->size;
 
        return scriptlet->data;
 }
 
-static int pakfire_scriptlet_is_shell_script(struct pakfire_scriptlet* scriptlet) {
+static int pakfire_scriptlet_is_shell_script(pakfire_scriptlet* scriptlet) {
        const char* interpreter = "#!/bin/sh";
 
        // data must be long enough
@@ -178,7 +178,7 @@ static int pakfire_scriptlet_is_shell_script(struct pakfire_scriptlet* scriptlet
        return 0;
 }
 
-int pakfire_scriptlet_execute(struct pakfire_scriptlet* scriptlet, struct pakfire* pakfire) {
+int pakfire_scriptlet_execute(pakfire_scriptlet* scriptlet, struct pakfire* pakfire) {
        // Detect what kind of script this is and run it
        if (pakfire_scriptlet_is_shell_script(scriptlet))
                return pakfire_jail_run_script(pakfire, scriptlet->data, scriptlet->size, NULL, NULL, 0);
index 146fa96fc47fd5f99ba1d55c70c9205db143afaa..b53586836354de942efa66d6695520fbb2743ef6 100644 (file)
 
 extern const char* pakfire_scriptlet_types[13];
 
-struct pakfire_scriptlet;
+typedef struct pakfire_scriptlet pakfire_scriptlet;
 
-int pakfire_scriptlet_create(struct pakfire_scriptlet** scriptlet,
+int pakfire_scriptlet_create(pakfire_scriptlet** scriptlet,
        pakfire_ctx* ctx, const char* type, const char* data, size_t size);
-struct pakfire_scriptlet* pakfire_scriptlet_ref(struct pakfire_scriptlet* scriptlet);
-struct pakfire_scriptlet* pakfire_scriptlet_unref(struct pakfire_scriptlet* scriptlet);
+pakfire_scriptlet* pakfire_scriptlet_ref(pakfire_scriptlet* scriptlet);
+pakfire_scriptlet* pakfire_scriptlet_unref(pakfire_scriptlet* scriptlet);
 
-const char* pakfire_scriptlet_get_type(struct pakfire_scriptlet* scriptlet);
-const char* pakfire_scriptlet_get_data(struct pakfire_scriptlet* scriptlet, size_t* size);
+const char* pakfire_scriptlet_get_type(pakfire_scriptlet* scriptlet);
+const char* pakfire_scriptlet_get_data(pakfire_scriptlet* scriptlet, size_t* size);
 
-int pakfire_scriptlet_execute(struct pakfire_scriptlet* scriptlet, struct pakfire* pakfire);
+int pakfire_scriptlet_execute(pakfire_scriptlet* scriptlet, struct pakfire* pakfire);
 
 #endif /* PAKFIRE_SCRIPTLET_H */
index 1955d017607f31525251acdf115aed87c43b08f0..ea79d719d2003735674cd7f21adb1b6583578c19 100644 (file)
@@ -1301,7 +1301,7 @@ static int pakfire_transaction_verify(struct pakfire_transaction* transaction,
 
 static int pakfire_transaction_run_script(struct pakfire_transaction* transaction,
                pakfire_db* db, const char* type, pakfire_package* pkg, pakfire_archive* archive) {
-       struct pakfire_scriptlet* scriptlet = NULL;
+       pakfire_scriptlet* scriptlet = NULL;
 
        // Fetch scriptlet from archive if possible
        if (archive)