From: Michael Tremer Date: Tue, 6 Jul 2021 13:51:18 +0000 (+0000) Subject: request: Implement optional downgrade/uninstall on install/update X-Git-Tag: 0.9.28~1104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a005d132725cb2ae2f46f8e2feae70cf8f8e8346;p=pakfire.git request: Implement optional downgrade/uninstall on install/update Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index e1507af8e..9b46bd349 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -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); diff --git a/src/libpakfire/include/pakfire/request.h b/src/libpakfire/include/pakfire/request.h index 574e02e37..7b8b2c0ee 100644 --- a/src/libpakfire/include/pakfire/request.h +++ b/src/libpakfire/include/pakfire/request.h @@ -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, }; diff --git a/src/libpakfire/request.c b/src/libpakfire/request.c index 02f5d2d27..8f2126d2f 100644 --- a/src/libpakfire/request.c +++ b/src/libpakfire/request.c @@ -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) diff --git a/src/pakfire/cli.py b/src/pakfire/cli.py index 85317c798..96605f3c3 100644 --- a/src/pakfire/cli.py +++ b/src/pakfire/cli.py @@ -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: