]> git.ipfire.org Git - pakfire.git/commitdiff
request: Implement optional downgrade/uninstall on install/update
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Jul 2021 13:51:18 +0000 (13:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Jul 2021 13:51:18 +0000 (13:51 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/include/pakfire/request.h
src/libpakfire/request.c
src/pakfire/cli.py

index e1507af8e73e0f909896edbeb8f28ab1022fd77f..9b46bd34982a39a0fd4eeaa706cbab559b7e219c 100644 (file)
@@ -276,20 +276,33 @@ static PyObject* Pakfire_install(PakfireObject* self, PyObject* args, PyObject*
        char* kwlist[] = {
                "packages",
                "without_recommended",
+               "allow_uninstall",
+               "allow_downgrade",
                NULL
        };
        char** packages = NULL;
        int without_recommended = 0;
+       int allow_uninstall = 0;
+       int allow_downgrade = 0;
        int solver_flags = 0;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$p", kwlist,
-                       convert_packages, &packages, &without_recommended))
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$ppp", kwlist,
+                       convert_packages, &packages, &without_recommended, &allow_uninstall,
+                       &allow_downgrade))
                return NULL;
 
        // Do not install recommended packages
        if (without_recommended)
                solver_flags |= PAKFIRE_REQUEST_WITHOUT_RECOMMENDED;
 
+       // Can the solver uninstall packages?
+       if (allow_uninstall)
+               solver_flags |= PAKFIRE_REQUEST_ALLOW_UNINSTALL;
+
+       // Can the solver downgrade packages?
+       if (allow_downgrade)
+               solver_flags |= PAKFIRE_REQUEST_ALLOW_DOWNGRADE;
+
        // Run pakfire_install
        int r = pakfire_install(self->pakfire, solver_flags, (const char**)packages, NULL, 0, NULL);
        if (r)
@@ -345,19 +358,32 @@ static PyObject* Pakfire_update(PakfireObject* self, PyObject* args, PyObject* k
        char* kwlist[] = {
                "packages",
                "excludes",
+               "allow_uninstall",
+               "allow_downgrade",
                NULL
        };
        char** packages = NULL;
        char** excludes = NULL;
-       int flags = 0;
+       int allow_uninstall = 0;
+       int allow_downgrade = 0;
+       int solver_flags = 0;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&", kwlist,
-                       convert_packages, &packages, convert_packages, &excludes))
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&pp", kwlist,
+                       convert_packages, &packages, convert_packages, &excludes,
+                       &allow_uninstall, &allow_downgrade))
                return NULL;
 
+       // Can the solver uninstall packages?
+       if (allow_uninstall)
+               solver_flags |= PAKFIRE_REQUEST_ALLOW_UNINSTALL;
+
+       // Can the solver downgrade packages?
+       if (allow_downgrade)
+               solver_flags |= PAKFIRE_REQUEST_ALLOW_DOWNGRADE;
+
        // Run pakfire_update
-       int r = pakfire_update(self->pakfire, 0, (const char**)packages,
-               (const char**)excludes, flags, NULL);
+       int r = pakfire_update(self->pakfire, solver_flags, (const char**)packages,
+               (const char**)excludes, 0, NULL);
        if (r)
                PyErr_SetFromErrno(PyExc_OSError);
 
index 574e02e377aaa7c51b5f706f32f7670f4f39c994..7b8b2c0ee0b9313c1d051f61628cca85e83d2eec 100644 (file)
@@ -31,16 +31,16 @@ struct pakfire_request;
 
 enum pakfire_request_flags {
        PAKFIRE_REQUEST_WITHOUT_RECOMMENDED = 1 << 0,
+       PAKFIRE_REQUEST_ALLOW_UNINSTALL     = 1 << 1,
+       PAKFIRE_REQUEST_ALLOW_DOWNGRADE     = 1 << 2,
 };
 
 enum pakfire_request_job_flags {
-       PAKFIRE_REQUEST_KEEP_DEPS         = 1 << 0,
-       PAKFIRE_REQUEST_KEEP_ORPHANED     = 1 << 1,
+       PAKFIRE_REQUEST_KEEP_DEPS           = 1 << 0,
+       PAKFIRE_REQUEST_KEEP_ORPHANED       = 1 << 1,
 };
 
 enum _pakfire_solver_flags {
-       PAKFIRE_SOLVER_ALLOW_UNINSTALL    = 1 << 0,
-       PAKFIRE_SOLVER_ALLOW_DOWNGRADE    = 1 << 3,
        PAKFIRE_SOLVER_ALLOW_VENDORCHANGE = 1 << 4,
 };
 
index 02f5d2d27d5fb62dc02551852760d575ae7c2363..8f2126d2fd1e30506a33f762b3469336514f4b4e 100644 (file)
@@ -109,10 +109,12 @@ static void pakfire_request_lock_running_kernel(struct pakfire_request* request)
 }
 
 static int setup_solver(struct pakfire_request* request, int flags) {
-       if (flags & PAKFIRE_SOLVER_ALLOW_DOWNGRADE)
+       // Can the solver downgrade packages?
+       if (flags & PAKFIRE_REQUEST_ALLOW_DOWNGRADE)
                solver_set_flag(request->solver, SOLVER_FLAG_ALLOW_DOWNGRADE, 1);
 
-       if (flags & PAKFIRE_SOLVER_ALLOW_UNINSTALL)
+       // Can the solver uninstall packages?
+       if (flags & PAKFIRE_REQUEST_ALLOW_UNINSTALL)
                solver_set_flag(request->solver, SOLVER_FLAG_ALLOW_UNINSTALL, 1);
 
        if (flags & PAKFIRE_SOLVER_ALLOW_VENDORCHANGE)
index 85317c798aa950010315fc984a49f596b18b6fd5..96605f3c3a2a427428bfa2ecace5ba3f91d3d542 100644 (file)
@@ -84,6 +84,10 @@ class Cli(object):
                        help=_("Give name of at least one package to install"))
                install.add_argument("--without-recommended", action="store_true",
                        help=_("Don't install recommended packages"))
+               install.add_argument("--allow-uninstall", action="store_true",
+                       help=_("Allow uninstalling packages"))
+               install.add_argument("--allow-downgrade", action="store_true",
+                       help=_("Allow downgrading packages"))
                install.set_defaults(func=self.handle_install)
 
                # provides
@@ -138,6 +142,10 @@ class Cli(object):
                        help=_("Give a name of a package to update or leave emtpy for all"))
                update.add_argument("--exclude", "-x", nargs="+", default=[],
                        help=_("Exclude package from update"))
+               update.add_argument("--allow-uninstall", action="store_true",
+                       help=_("Allow uninstalling packages"))
+               update.add_argument("--allow-downgrade", action="store_true",
+                       help=_("Allow downgrading packages"))
                update.set_defaults(func=self.handle_update)
 
                return parser.parse_args()
@@ -257,6 +265,8 @@ class Cli(object):
                p.update(
                        ns.package,
                        excludes=ns.exclude,
+                       allow_uninstall=ns.allow_uninstall,
+                       allow_downgrade=ns.allow_downgrade,
                )
 
        def handle_sync(self, ns):
@@ -264,7 +274,12 @@ class Cli(object):
 
        def handle_install(self, ns):
                p = self.pakfire(ns)
-               p.install(ns.package, without_recommended=not ns.without_recommended)
+               p.install(
+                       ns.package,
+                       without_recommended=ns.without_recommended,
+                       allow_uninstall=ns.allow_uninstall,
+                       allow_downgrade=ns.allow_downgrade,
+               )
 
        def handle_reinstall(self, ns):
                with self.pakfire(ns) as p: