]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Add a simple function to install packages
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 7 Feb 2025 23:05:04 +0000 (23:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 7 Feb 2025 23:05:04 +0000 (23:05 +0000)
This will come handy when generating images.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/pakfire.c
src/pakfire/pakfire.h

index fdbc65c205c795b3fade112033de588e2ecf4729..08a17ccb9148f2fddae42098d7cfcf263f65784f 100644 (file)
@@ -1926,3 +1926,46 @@ ERROR:
 
        return r;
 }
+
+/*
+ * Convenience function to install a couple of packages. Simple.
+ */
+int pakfire_install(struct pakfire* self, const char** packages) {
+       struct pakfire_transaction* transaction = NULL;
+       char* problems = NULL;
+       int r;
+
+       // Create a new transaction
+       r = pakfire_transaction_create(&transaction, self, 0);
+       if (r < 0)
+               goto ERROR;
+
+       // Install all packages
+       for (const char** package = packages; *package; package++) {
+               r = pakfire_transaction_request(transaction, PAKFIRE_JOB_INSTALL, *package, 0);
+               if (r < 0)
+                       goto ERROR;
+       }
+
+       // Solve the transaction
+       r = pakfire_transaction_solve(transaction, 0, &problems);
+       if (r) {
+               if (problems)
+                       ERROR(self->ctx, "Could not install packages:\n%s\n", problems);
+
+               goto ERROR;
+       }
+
+       // Run the transaction
+       r = pakfire_transaction_run(transaction);
+       if (r < 0)
+               goto ERROR;
+
+ERROR:
+       if (transaction)
+               pakfire_transaction_unref(transaction);
+       if (problems)
+               free(problems);
+
+       return r;
+}
index b23ab4b64265c34c1939b8fd80809bd5008be3fa..c15f54f8ef385abc3a890886f80acb774d34abb3 100644 (file)
@@ -155,4 +155,6 @@ int pakfire_repo_walk(struct pakfire* pakfire,
 struct archive* pakfire_get_disk_reader(struct pakfire* pakfire);
 struct archive* pakfire_get_disk_writer(struct pakfire* pakfire);
 
+int pakfire_install(struct pakfire* self, const char** packages);
+
 #endif /* PAKFIRE_PAKFIRE_H */