]> git.ipfire.org Git - pakfire.git/commitdiff
check: Verify all package dependencies
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Jun 2021 15:47:32 +0000 (15:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Jun 2021 15:47:32 +0000 (15:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index 362f6beca842bb88daf74ef545c67ddf6fb3013f..0fae1c0e0fc984019470f17296474580765c1744 100644 (file)
@@ -1682,6 +1682,62 @@ PAKFIRE_EXPORT int pakfire_update(Pakfire pakfire, const char** packages,
                flags, changed);
 }
 
+static int pakfire_perform_transaction_simple(Pakfire pakfire,
+               int (*action)(struct pakfire_request* request), int* changed) {
+       struct pakfire_request* request = NULL;
+       struct pakfire_transaction* transaction = NULL;
+       int r = 1;
+
+       // Refresh repositories
+       r = pakfire_refresh(pakfire, 0);
+       if (r)
+               goto ERROR;
+
+       // Create a new request
+       r = pakfire_request_create(&request, pakfire, 0);
+       if (r)
+               goto ERROR;
+
+       // Perform action
+       r = action(request);
+       if (r)
+               goto ERROR;
+
+       // Solve the request
+       r = pakfire_request_solve(request, 0);
+       if (r)
+               goto ERROR;
+
+       // Fetch the transaction
+       transaction = pakfire_request_get_transaction(request);
+       if (!transaction)
+               goto ERROR;
+
+       // Set how many packages have been changed
+       if (changed)
+               *changed = pakfire_transaction_count(transaction);
+
+       // Run the transaction
+       r = pakfire_transaction_run(transaction);
+       if (r)
+               goto ERROR;
+
+       // Success
+       r = 0;
+
+ERROR:
+       if (transaction)
+               pakfire_transaction_unref(transaction);
+       if (request)
+               pakfire_request_unref(request);
+
+       return r;
+}
+
+static int pakfire_verify(Pakfire pakfire, int *changed) {
+       return pakfire_perform_transaction_simple(pakfire, pakfire_request_verify, changed);
+}
+
 PAKFIRE_EXPORT int pakfire_check(Pakfire pakfire) {
        struct pakfire_db* db = NULL;
        int r;
@@ -1696,6 +1752,11 @@ PAKFIRE_EXPORT int pakfire_check(Pakfire pakfire) {
        if (r)
                goto ERROR;
 
+       // Check if all dependencies are intact
+       r = pakfire_verify(pakfire, NULL);
+       if (r)
+               goto ERROR;
+
 ERROR:
        if (db)
                pakfire_db_unref(db);