From: Michael Tremer Date: Mon, 21 Jun 2021 17:35:18 +0000 (+0000) Subject: cli: Allow to exclude packages from update X-Git-Tag: 0.9.28~1205 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9b18fbdd5fffeeb2e08a4e4b9acbf905293b596;p=pakfire.git cli: Allow to exclude packages from update Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index 764f0f1d3..6a58e561f 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -218,10 +218,6 @@ static int convert_packages(PyObject* object, void* address) { } const unsigned int length = PySequence_Length(object); - if (!length) { - PyErr_SetString(PyExc_ValueError, "Packages list is empty"); - goto ERROR; - } // Allocate array *packages = calloc(length + 1, sizeof(*packages)); @@ -288,7 +284,7 @@ static PyObject* Pakfire_install(PakfireObject* self, PyObject* args, PyObject* // XXX include_recommended // Run pakfire_install - int r = pakfire_install(self->pakfire, (const char**)packages, flags, NULL); + int r = pakfire_install(self->pakfire, (const char**)packages, NULL, flags, NULL); if (r) PyErr_SetFromErrno(PyExc_OSError); @@ -317,7 +313,7 @@ static PyObject* Pakfire_erase(PakfireObject* self, PyObject* args, PyObject* kw return NULL; // Run pakfire_erase - int r = pakfire_erase(self->pakfire, (const char**)packages, flags, NULL); + int r = pakfire_erase(self->pakfire, (const char**)packages, NULL, flags, NULL); if (r) PyErr_SetFromErrno(PyExc_OSError); @@ -336,17 +332,20 @@ static PyObject* Pakfire_erase(PakfireObject* self, PyObject* args, PyObject* kw static PyObject* Pakfire_update(PakfireObject* self, PyObject* args, PyObject* kwargs) { char* kwlist[] = { "packages", + "excludes", "allow_archchange", "allow_vendorchange", NULL }; char** packages = NULL; + char** excludes = NULL; int allow_archchange = 0; int allow_vendorchange = 0; int flags = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$pp", kwlist, - convert_packages, &packages, &allow_archchange, &allow_vendorchange)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&pp", kwlist, + convert_packages, &packages, convert_packages, &excludes, + &allow_archchange, &allow_vendorchange)) return NULL; if (allow_archchange) @@ -356,7 +355,8 @@ static PyObject* Pakfire_update(PakfireObject* self, PyObject* args, PyObject* k flags |= PAKFIRE_SOLVER_ALLOW_VENDORCHANGE; // Run pakfire_update - int r = pakfire_update(self->pakfire, (const char**)packages, flags, NULL); + int r = pakfire_update(self->pakfire, (const char**)packages, + (const char**)excludes, flags, NULL); if (r) PyErr_SetFromErrno(PyExc_OSError); @@ -366,6 +366,12 @@ static PyObject* Pakfire_update(PakfireObject* self, PyObject* args, PyObject* k free(packages); } + if (excludes) { + for (char** exclude = excludes; *exclude; exclude++) + free(*exclude); + free(excludes); + } + if (r) return NULL; diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 4971853e8..ba4e9c8ba 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -78,7 +78,7 @@ static int pakfire_build_install_packages(Pakfire pakfire, int* snapshot_needs_u int changed = 0; // Install everything - r = pakfire_install(pakfire, (const char**)packages, 0, &changed); + r = pakfire_install(pakfire, (const char**)packages, NULL, 0, &changed); if (r) { ERROR(pakfire, "Could not install build dependencies\n"); goto ERROR; @@ -873,7 +873,7 @@ PAKFIRE_EXPORT int pakfire_build(Pakfire pakfire, const char* path, }; // Install the package into the build environment - r = pakfire_install(pakfire, packages, 0, NULL); + r = pakfire_install(pakfire, packages, NULL, 0, NULL); if (r) { ERROR(pakfire, "Could not install %s\n", path); goto ERROR; diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 08900db40..248fd47e7 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -77,9 +77,12 @@ void pakfire_log_set_priority(Pakfire pakfire, int priority); // Install/Erase/Update -int pakfire_install(Pakfire pakfire, const char** packages, int flags, int* changed); -int pakfire_erase(Pakfire pakfire, const char** packages, int flags, int* changed); -int pakfire_update(Pakfire pakfire, const char** packages, int flags, int* changed); +int pakfire_install(Pakfire pakfire, const char** packages, const char** locks, + int flags, int* changed); +int pakfire_erase(Pakfire pakfire, const char** packages, const char** locks, + int flags, int* changed); +int pakfire_update(Pakfire pakfire, const char** packages, const char** locks, + int flags, int* changed); // Check diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 6b9d225dc..67829d6f8 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -1603,7 +1603,7 @@ struct archive* pakfire_make_archive_disk_writer(Pakfire pakfire) { static int pakfire_perform_transaction(Pakfire pakfire, int (*action)(struct pakfire_request* request, const char* what, int flags), - const char** packages, int flags, int* changed) { + const char** packages, const char** locks, int flags, int* changed) { struct pakfire_request* request = NULL; struct pakfire_transaction* transaction = NULL; int r = 1; @@ -1624,6 +1624,15 @@ static int pakfire_perform_transaction(Pakfire pakfire, if (r) goto ERROR; + // Lock anything that should be locked + for (const char** lock = locks; *lock; lock++) { + r = pakfire_request_lock(request, *lock); + if (r) { + ERROR(pakfire, "Could not lock '%s': %m\n", *lock); + goto ERROR; + } + } + // Perform action on all packages for (const char** package = packages; *package; package++) { r = action(request, *package, flags); @@ -1665,21 +1674,21 @@ ERROR: } PAKFIRE_EXPORT int pakfire_install(Pakfire pakfire, const char** packages, - int flags, int* changed) { + const char** locks, int flags, int* changed) { return pakfire_perform_transaction(pakfire, pakfire_request_install, packages, - flags, changed); + locks, flags, changed); } PAKFIRE_EXPORT int pakfire_erase(Pakfire pakfire, const char** packages, - int flags, int* changed) { + const char** locks, int flags, int* changed) { return pakfire_perform_transaction(pakfire, pakfire_request_erase, packages, - flags, changed); + locks, flags, changed); } PAKFIRE_EXPORT int pakfire_update(Pakfire pakfire, const char** packages, - int flags, int* changed) { + const char** locks, int flags, int* changed) { return pakfire_perform_transaction(pakfire, pakfire_request_upgrade, packages, - flags, changed); + locks, flags, changed); } static int pakfire_perform_transaction_simple(Pakfire pakfire, diff --git a/src/pakfire/cli.py b/src/pakfire/cli.py index ab21ca9dc..c8370eec0 100644 --- a/src/pakfire/cli.py +++ b/src/pakfire/cli.py @@ -131,6 +131,8 @@ class Cli(object): help=_("Allow changing the architecture of packages")) update.add_argument("--allow-vendorchange", action="store_true", help=_("Allow changing the vendor of packages")) + update.add_argument("--exclude", "-x", nargs="+", default=[], + help=_("Exclude package from update")) update.set_defaults(func=self.handle_update) return parser.parse_args() @@ -249,6 +251,7 @@ class Cli(object): p = self.pakfire(ns) p.update( ns.package, + excludes=ns.exclude, allow_archchange=ns.allow_archchange, allow_vendorchange=ns.allow_vendorchange, )