]> git.ipfire.org Git - pakfire.git/commitdiff
cli: Allow to exclude packages from update
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Jun 2021 17:35:18 +0000 (17:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 21 Jun 2021 17:35:18 +0000 (17:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/_pakfire/pakfire.c
src/libpakfire/build.c
src/libpakfire/include/pakfire/pakfire.h
src/libpakfire/pakfire.c
src/pakfire/cli.py

index 764f0f1d37946b53cdf4a952e31806ee1487387f..6a58e561f3d1397f6f49ba8820241e3b2ca6d68b 100644 (file)
@@ -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;
 
index 4971853e8115cee80c5fb2bdbad859de6857f488..ba4e9c8ba0dc985a55de1a444816826bdceea58d 100644 (file)
@@ -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;
index 08900db40073af226edb708a481b70801733505a..248fd47e710ed5cc5ceddeef0e24a61b9800ea78 100644 (file)
@@ -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
 
index 6b9d225dc25ef253f28f9b279fd07141f2b4c494..67829d6f8318ab95586b4049bb3ad426c9e96413 100644 (file)
@@ -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,
index ab21ca9dc77e47984f74ea00fdf2406d497a1ca1..c8370eec0d9d83cbe64e4d2e4d459a386b15e237 100644 (file)
@@ -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,
                )