]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: Implement "check" command
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Jun 2021 10:58:31 +0000 (10:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Jun 2021 10:58:31 +0000 (10:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/libpakfire.sym
src/libpakfire/pakfire.c
src/pakfire/cli.py

index 6a32772c0d803c6e87eb58e115d9d62ec248e8af..400db9cc329f6cff2b32014fa5bfae67e0ca6b5f 100644 (file)
@@ -1042,6 +1042,16 @@ static PyObject* Pakfire_refresh(PakfireObject* self, PyObject* args) {
        Py_RETURN_NONE;
 }
 
+static PyObject* Pakfire_check(PakfireObject* self) {
+       int r = pakfire_check(self->pakfire);
+       if (r) {
+               PyErr_SetFromErrno(PyExc_OSError);
+               return NULL;
+       }
+
+       Py_RETURN_NONE;
+}
+
 static struct PyMethodDef Pakfire_methods[] = {
        {
                "bind",
@@ -1055,6 +1065,12 @@ static struct PyMethodDef Pakfire_methods[] = {
                METH_VARARGS|METH_KEYWORDS,
                NULL
        },
+       {
+               "check",
+               (PyCFunction)Pakfire_check,
+               METH_NOARGS,
+               NULL,
+       },
        {
                "clean",
                (PyCFunction)Pakfire_clean,
index 16faa7a58f4973b85e7a9aeb1bf68118c779e1e2..2eed931cee12b5da64084df30672f1c339ca6fa5 100644 (file)
@@ -86,6 +86,10 @@ int pakfire_install(Pakfire pakfire, const char** packages, int flags, int* chan
 int pakfire_erase(Pakfire pakfire, const char** packages, int flags, int* changed);
 int pakfire_update(Pakfire pakfire, const char** packages, int flags, int* changed);
 
+// Check
+
+int pakfire_check(Pakfire pakfire);
+
 #ifdef PAKFIRE_PRIVATE
 
 #include <solv/pool.h>
index 393b1b90bb2fae032f48e65a2d8ab7dac4037487..8e519c5ba0825ddb4ea3a7b0db5f3194ccc4fb12 100644 (file)
@@ -22,6 +22,7 @@ LIBPAKFIRE_0 {
 global:
        # pakfire
        pakfire_bind;
+       pakfire_check;
        pakfire_clean;
        pakfire_copy_in;
        pakfire_copy_out;
index 20dd54933749574d620251a3050966e378bed886..362f6beca842bb88daf74ef545c67ddf6fb3013f 100644 (file)
@@ -1681,3 +1681,24 @@ PAKFIRE_EXPORT int pakfire_update(Pakfire pakfire, const char** packages,
        return pakfire_perform_transaction(pakfire, pakfire_request_upgrade, packages,
                flags, changed);
 }
+
+PAKFIRE_EXPORT int pakfire_check(Pakfire pakfire) {
+       struct pakfire_db* db = NULL;
+       int r;
+
+       // Open database in read-only mode and try to load all installed packages
+       r = pakfire_db_open(&db, pakfire, PAKFIRE_DB_READWRITE);
+       if (r)
+               goto ERROR;
+
+       // Perform a database integrity check
+       r = pakfire_db_check(db);
+       if (r)
+               goto ERROR;
+
+ERROR:
+       if (db)
+               pakfire_db_unref(db);
+
+       return r;
+}
index 03f8a74bc0e93c9ed8dc37709cdf05100045c08c..0250d2a8e3637398ec457b3c51c2823dc9e2df78 100644 (file)
@@ -303,12 +303,7 @@ class Cli(object):
                p.clean()
 
        def handle_check(self, ns):
-               with self.pakfire(ns) as p:
-                       # This will throw an exception when there are errors
-                       transaction = p.check()
-
-                       print(_("Everything okay"))
-
+               self.pakfire(ns).check()
 
 
 class CliClient(Cli):