From: Michael Tremer Date: Thu, 29 Apr 2021 22:49:15 +0000 (+0000) Subject: Drop relations entirely X-Git-Tag: 0.9.28~1285^2~186 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2df5069377f58953ed8f6aa338312facd6abef17;p=pakfire.git Drop relations entirely Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index ef9038756..539895511 100644 --- a/Makefile.am +++ b/Makefile.am @@ -177,8 +177,6 @@ _pakfire_la_SOURCES = \ src/_pakfire/problem.h \ src/_pakfire/progressbar.c \ src/_pakfire/progressbar.h \ - src/_pakfire/relation.c \ - src/_pakfire/relation.h \ src/_pakfire/repo.c \ src/_pakfire/repo.h \ src/_pakfire/request.c \ @@ -261,8 +259,6 @@ libpakfire_la_SOURCES = \ src/libpakfire/problem.c \ src/libpakfire/progressbar.c \ src/libpakfire/pwd.c \ - src/libpakfire/relation.c \ - src/libpakfire/relationlist.c \ src/libpakfire/repo.c \ src/libpakfire/repolist.c \ src/libpakfire/request.c \ @@ -297,8 +293,6 @@ pkginclude_HEADERS += \ src/libpakfire/include/pakfire/problem.h \ src/libpakfire/include/pakfire/progressbar.h \ src/libpakfire/include/pakfire/pwd.h \ - src/libpakfire/include/pakfire/relation.h \ - src/libpakfire/include/pakfire/relationlist.h \ src/libpakfire/include/pakfire/repo.h \ src/libpakfire/include/pakfire/repolist.h \ src/libpakfire/include/pakfire/request.h \ diff --git a/src/_pakfire/_pakfiremodule.c b/src/_pakfire/_pakfiremodule.c index 4b1fc4ed0..557348549 100644 --- a/src/_pakfire/_pakfiremodule.c +++ b/src/_pakfire/_pakfiremodule.c @@ -31,7 +31,6 @@ #include "parser.h" #include "problem.h" #include "progressbar.h" -#include "relation.h" #include "repo.h" #include "request.h" #include "solution.h" @@ -156,13 +155,6 @@ PyMODINIT_FUNC PyInit__pakfire(void) { Py_INCREF(&RepoType); PyModule_AddObject(module, "Repo", (PyObject *)&RepoType); - // Relation - if (PyType_Ready(&RelationType) < 0) - return NULL; - - Py_INCREF(&RelationType); - PyModule_AddObject(module, "Relation", (PyObject *)&RelationType); - // Request if (PyType_Ready(&RequestType) < 0) return NULL; diff --git a/src/_pakfire/package.c b/src/_pakfire/package.c index b378e84ba..3773a5cf0 100644 --- a/src/_pakfire/package.c +++ b/src/_pakfire/package.c @@ -23,13 +23,11 @@ #include #include #include -#include #include #include #include "package.h" #include "pakfire.h" -#include "relation.h" #include "repo.h" PyObject* new_package(PyTypeObject* type, PakfirePackage pkg) { diff --git a/src/_pakfire/relation.c b/src/_pakfire/relation.c deleted file mode 100644 index ac4f21cc6..000000000 --- a/src/_pakfire/relation.c +++ /dev/null @@ -1,137 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2011 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#include - -#include -#include -#include -#include -#include - -#include "package.h" -#include "relation.h" - -PyObject* new_relation(PyTypeObject* type, PakfireRelation relation) { - RelationObject* self = (RelationObject *)type->tp_alloc(type, 0); - if (self) { - self->relation = pakfire_relation_ref(relation); - } - - return (PyObject*)self; -} - -static PyObject* Relation_new(PyTypeObject* type, PyObject* args, PyObject* kwds) { - RelationObject* self = (RelationObject *)type->tp_alloc(type, 0); - if (self) { - self->relation = NULL; - } - - return (PyObject*)self; -} - -static void Relation_dealloc(RelationObject* self) { - pakfire_relation_unref(self->relation); - - Py_TYPE(self)->tp_free((PyObject *)self); -} - -static int Relation_init(RelationObject* self, PyObject* args, PyObject* kwds) { - PakfireObject* pakfire; - const char* relation; - - if (!PyArg_ParseTuple(args, "O!s", &PakfireType, &pakfire, &relation)) - return -1; - - self->relation = pakfire_relation_create_from_string(pakfire->pakfire, relation); - if (!self->relation) { - PyErr_Format(PyExc_ValueError, "No such relation: %s", relation); - return -1; - } - - return 0; -} - -static long Relation_hash(RelationObject* self) { - return pakfire_relation_get_id(self->relation); -} - -static PyObject* Relation_repr(RelationObject* self) { - char* relation = pakfire_relation_str(self->relation); - - PyObject* repr = PyUnicode_FromFormat("<_pakfire.Relation %s>", relation); - free(relation); - - return repr; -} - -static PyObject* Relation_str(RelationObject* self) { - char* relation = pakfire_relation_str(self->relation); - - PyObject* str = PyUnicode_FromString(relation); - free(relation); - - return str; -} - -static PyObject* Relation_get_providers(RelationObject* self) { - PakfirePackageList packagelist = pakfire_relation_providers(self->relation); - - PyObject* list = PyList_New(0); - for (unsigned int i = 0; i < pakfire_packagelist_count(packagelist); i++) { - PakfirePackage package = pakfire_packagelist_get(packagelist, i); - - PyObject* obj = new_package(&PackageType, package); - PyList_Append(list, obj); - - pakfire_package_unref(package); - Py_DECREF(obj); - } - - pakfire_packagelist_unref(packagelist); - - return list; -} - -static struct PyGetSetDef Relation_getsetters[] = { - { - "providers", - (getter)Relation_get_providers, - NULL, - NULL, - NULL - }, - { NULL }, -}; - -PyTypeObject RelationType = { - PyVarObject_HEAD_INIT(NULL, 0) - tp_name: "_pakfire.Relation", - tp_basicsize: sizeof(RelationObject), - tp_flags: Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, - tp_new: Relation_new, - tp_dealloc: (destructor)Relation_dealloc, - tp_init: (initproc)Relation_init, - tp_doc: "Relation object", - tp_hash: (hashfunc)Relation_hash, - tp_repr: (reprfunc)Relation_repr, - tp_str: (reprfunc)Relation_str, - tp_getset: Relation_getsetters, -}; diff --git a/src/_pakfire/relation.h b/src/_pakfire/relation.h deleted file mode 100644 index 412b5b1be..000000000 --- a/src/_pakfire/relation.h +++ /dev/null @@ -1,39 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2011 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#ifndef PYTHON_PAKFIRE_RELATION_H -#define PYTHON_PAKFIRE_RELATION_H - -#include - -#include - -#include "pakfire.h" - -typedef struct { - PyObject_HEAD - PakfireRelation relation; -} RelationObject; - -extern PyTypeObject RelationType; - -PyObject* new_relation(PyTypeObject* type, PakfireRelation relation); - -#endif /* PYTHON_PAKFIRE_RELATION_H */ diff --git a/src/_pakfire/request.c b/src/_pakfire/request.c index e1ec3cbbd..eef117f2e 100644 --- a/src/_pakfire/request.c +++ b/src/_pakfire/request.c @@ -26,7 +26,6 @@ #include "package.h" #include "pakfire.h" #include "problem.h" -#include "relation.h" #include "request.h" #include "transaction.h" diff --git a/src/libpakfire/db.c b/src/libpakfire/db.c index 27cde2ba9..20a860279 100644 --- a/src/libpakfire/db.c +++ b/src/libpakfire/db.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include diff --git a/src/libpakfire/include/pakfire/package.h b/src/libpakfire/include/pakfire/package.h index 2457086f5..e4e04a158 100644 --- a/src/libpakfire/include/pakfire/package.h +++ b/src/libpakfire/include/pakfire/package.h @@ -24,8 +24,6 @@ #include #include -#include -#include #include PakfirePackage pakfire_package_create(Pakfire pakfire, PakfireRepo repo, diff --git a/src/libpakfire/include/pakfire/relation.h b/src/libpakfire/include/pakfire/relation.h deleted file mode 100644 index d76bcf4cd..000000000 --- a/src/libpakfire/include/pakfire/relation.h +++ /dev/null @@ -1,44 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2013 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#ifndef PAKFIRE_RELATION_H -#define PAKFIRE_RELATION_H - -#include -#include -#include - -#include - -PakfireRelation pakfire_relation_create(Pakfire pakfire, const char* name, int cmp_type, const char* evr); -PakfireRelation pakfire_relation_create_from_id(Pakfire pakfire, Id id); -PakfireRelation pakfire_relation_create_from_string(Pakfire pakfire, const char* s); - -PakfireRelation pakfire_relation_ref(PakfireRelation relation); -PakfireRelation pakfire_relation_unref(PakfireRelation relation); - -Id pakfire_relation_get_id(PakfireRelation relation); -char* pakfire_relation_str(PakfireRelation relation); - -PakfirePackageList pakfire_relation_providers(PakfireRelation relation); - -int pakfire_relation2queue(const PakfireRelation relation, Queue* queue, int solver_action); - -#endif /* PAKFIRE_RELATION_H */ diff --git a/src/libpakfire/include/pakfire/relationlist.h b/src/libpakfire/include/pakfire/relationlist.h deleted file mode 100644 index 9ca38a0fb..000000000 --- a/src/libpakfire/include/pakfire/relationlist.h +++ /dev/null @@ -1,47 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2013 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#ifndef PAKFIRE_RELATIONLIST_H -#define PAKFIRE_RELATIONLIST_H - -#include - -int pakfire_relationlist_create(PakfireRelationList* list, Pakfire pakfire); -int pakfire_relationlist_create_from_string(PakfireRelationList* list, - Pakfire pakfire, const char* s); - -PakfireRelationList pakfire_relationlist_ref(PakfireRelationList relationlist); -PakfireRelationList pakfire_relationlist_unref(PakfireRelationList relationlist); - -void pakfire_relationlist_add(PakfireRelationList relationlist, PakfireRelation relation); -size_t pakfire_relationlist_size(PakfireRelationList relationlist); - -PakfireRelation pakfire_relationlist_get(PakfireRelationList relationlist, int index); - -void pakfire_relationlist_sort(PakfireRelationList list); - -#ifdef PAKFIRE_PRIVATE - -int pakfire_relationlist_from_queue(PakfireRelationList* list, Pakfire pakfire, Queue q); -Queue* pakfire_relationlist_get_queue(PakfireRelationList list); - -#endif - -#endif /* PAKFIRE_RELATIONLIST_H */ diff --git a/src/libpakfire/include/pakfire/types.h b/src/libpakfire/include/pakfire/types.h index 9af95f987..e394b23f8 100644 --- a/src/libpakfire/include/pakfire/types.h +++ b/src/libpakfire/include/pakfire/types.h @@ -33,8 +33,6 @@ typedef struct _PakfirePackage* PakfirePackage; typedef struct _PakfirePackageList* PakfirePackageList; typedef struct _PakfireParser* PakfireParser; typedef struct _PakfireProblem* PakfireProblem; -typedef struct _PakfireRelation* PakfireRelation; -typedef struct _PakfireRelationList* PakfireRelationList; typedef struct _PakfireRepo* PakfireRepo; typedef struct _PakfireSolution* PakfireSolution; typedef struct _PakfireStep* PakfireStep; diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index d8d1bc53b..7b9db5759 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -39,8 +39,6 @@ #include #include #include -#include -#include #include #include @@ -640,20 +638,6 @@ ERROR: return array; } -static void pakfire_package_set_relationlist(PakfirePackage pkg, Id type, - PakfireRelationList relationlist, Id marker) { - Solvable* s = get_solvable(pkg); - Queue* q = pakfire_relationlist_get_queue(relationlist); - -#if 0 - // This implemention should be the fastest, but unfortunately does not work. - solvable_set_deparray(s, type, q, marker); -#else - for (int i = 0; i < q->count; i++) - solvable_add_deparray(s, type, q->elements[i], marker); -#endif -} - static void pakfire_package_add_dep(PakfirePackage pkg, Id type, const char* dep, Id marker) { Solvable* s = get_solvable(pkg); @@ -670,11 +654,7 @@ PAKFIRE_EXPORT char** pakfire_package_get_provides(PakfirePackage pkg) { return pakfire_package_get_relationlist(pkg, SOLVABLE_PROVIDES, -SOLVABLE_FILEMARKER); } -PAKFIRE_EXPORT void pakfire_package_set_provides(PakfirePackage pkg, PakfireRelationList relationlist) { - pakfire_package_set_relationlist(pkg, SOLVABLE_PROVIDES, relationlist, -SOLVABLE_FILEMARKER); -} - -PAKFIRE_EXPORT void pakfire_package_add_provides(PakfirePackage pkg, const char* dep) { +void pakfire_package_add_provides(PakfirePackage pkg, const char* dep) { pakfire_package_add_dep(pkg, SOLVABLE_PROVIDES, dep, -SOLVABLE_FILEMARKER); } @@ -682,11 +662,7 @@ PAKFIRE_EXPORT char** pakfire_package_get_prerequires(PakfirePackage pkg) { return pakfire_package_get_relationlist(pkg, SOLVABLE_REQUIRES, SOLVABLE_PREREQMARKER); } -PAKFIRE_EXPORT void pakfire_package_set_prerequires(PakfirePackage pkg, PakfireRelationList relationlist) { - pakfire_package_set_relationlist(pkg, SOLVABLE_REQUIRES, relationlist, SOLVABLE_PREREQMARKER); -} - -PAKFIRE_EXPORT void pakfire_package_add_prerequires(PakfirePackage pkg, const char* dep) { +void pakfire_package_add_prerequires(PakfirePackage pkg, const char* dep) { pakfire_package_add_dep(pkg, SOLVABLE_REQUIRES, dep, SOLVABLE_PREREQMARKER); } @@ -694,11 +670,7 @@ PAKFIRE_EXPORT char** pakfire_package_get_requires(PakfirePackage pkg) { return pakfire_package_get_relationlist(pkg, SOLVABLE_REQUIRES, -SOLVABLE_PREREQMARKER); } -PAKFIRE_EXPORT void pakfire_package_set_requires(PakfirePackage pkg, PakfireRelationList relationlist) { - pakfire_package_set_relationlist(pkg, SOLVABLE_REQUIRES, relationlist, -SOLVABLE_PREREQMARKER); -} - -PAKFIRE_EXPORT void pakfire_package_add_requires(PakfirePackage pkg, const char* dep) { +void pakfire_package_add_requires(PakfirePackage pkg, const char* dep) { pakfire_package_add_dep(pkg, SOLVABLE_REQUIRES, dep, -SOLVABLE_PREREQMARKER); } @@ -706,11 +678,7 @@ PAKFIRE_EXPORT char** pakfire_package_get_conflicts(PakfirePackage pkg) { return pakfire_package_get_relationlist(pkg, SOLVABLE_CONFLICTS, 0); } -PAKFIRE_EXPORT void pakfire_package_set_conflicts(PakfirePackage pkg, PakfireRelationList relationlist) { - pakfire_package_set_relationlist(pkg, SOLVABLE_CONFLICTS, relationlist, 0); -} - -PAKFIRE_EXPORT void pakfire_package_add_conflicts(PakfirePackage pkg, const char* dep) { +void pakfire_package_add_conflicts(PakfirePackage pkg, const char* dep) { pakfire_package_add_dep(pkg, SOLVABLE_CONFLICTS, dep, 0); } @@ -718,11 +686,7 @@ PAKFIRE_EXPORT char** pakfire_package_get_obsoletes(PakfirePackage pkg) { return pakfire_package_get_relationlist(pkg, SOLVABLE_OBSOLETES, 0); } -PAKFIRE_EXPORT void pakfire_package_set_obsoletes(PakfirePackage pkg, PakfireRelationList relationlist) { - pakfire_package_set_relationlist(pkg, SOLVABLE_OBSOLETES, relationlist, 0); -} - -PAKFIRE_EXPORT void pakfire_package_add_obsoletes(PakfirePackage pkg, const char* dep) { +void pakfire_package_add_obsoletes(PakfirePackage pkg, const char* dep) { pakfire_package_add_dep(pkg, SOLVABLE_OBSOLETES, dep, 0); } @@ -730,11 +694,7 @@ PAKFIRE_EXPORT char** pakfire_package_get_recommends(PakfirePackage pkg) { return pakfire_package_get_relationlist(pkg, SOLVABLE_RECOMMENDS, 0); } -PAKFIRE_EXPORT void pakfire_package_set_recommends(PakfirePackage pkg, PakfireRelationList relationlist) { - pakfire_package_set_relationlist(pkg, SOLVABLE_RECOMMENDS, relationlist, 0); -} - -PAKFIRE_EXPORT void pakfire_package_add_recommends(PakfirePackage pkg, const char* dep) { +void pakfire_package_add_recommends(PakfirePackage pkg, const char* dep) { pakfire_package_add_dep(pkg, SOLVABLE_RECOMMENDS, dep, 0); } @@ -742,11 +702,7 @@ PAKFIRE_EXPORT char** pakfire_package_get_suggests(PakfirePackage pkg) { return pakfire_package_get_relationlist(pkg, SOLVABLE_SUGGESTS, 0); } -PAKFIRE_EXPORT void pakfire_package_set_suggests(PakfirePackage pkg, PakfireRelationList relationlist) { - pakfire_package_set_relationlist(pkg, SOLVABLE_SUGGESTS, relationlist, 0); -} - -PAKFIRE_EXPORT void pakfire_package_add_suggests(PakfirePackage pkg, const char* dep) { +void pakfire_package_add_suggests(PakfirePackage pkg, const char* dep) { pakfire_package_add_dep(pkg, SOLVABLE_SUGGESTS, dep, 0); } @@ -754,11 +710,7 @@ PAKFIRE_EXPORT char** pakfire_package_get_supplements(PakfirePackage pkg) { return pakfire_package_get_relationlist(pkg, SOLVABLE_SUPPLEMENTS, 0); } -PAKFIRE_EXPORT void pakfire_package_set_supplements(PakfirePackage pkg, PakfireRelationList relationlist) { - pakfire_package_set_relationlist(pkg, SOLVABLE_SUPPLEMENTS, relationlist, 0); -} - -PAKFIRE_EXPORT void pakfire_package_add_supplements(PakfirePackage pkg, const char* dep) { +void pakfire_package_add_supplements(PakfirePackage pkg, const char* dep) { pakfire_package_add_dep(pkg, SOLVABLE_SUPPLEMENTS, dep, 0); } @@ -766,11 +718,7 @@ PAKFIRE_EXPORT char** pakfire_package_get_enhances(PakfirePackage pkg) { return pakfire_package_get_relationlist(pkg, SOLVABLE_ENHANCES, 0); } -PAKFIRE_EXPORT void pakfire_package_set_enhances(PakfirePackage pkg, PakfireRelationList relationlist) { - pakfire_package_set_relationlist(pkg, SOLVABLE_ENHANCES, relationlist, 0); -} - -PAKFIRE_EXPORT void pakfire_package_add_enhances(PakfirePackage pkg, const char* dep) { +void pakfire_package_add_enhances(PakfirePackage pkg, const char* dep) { pakfire_package_add_dep(pkg, SOLVABLE_ENHANCES, dep, 0); } diff --git a/src/libpakfire/parser.c b/src/libpakfire/parser.c index 7b17a2712..a79413a71 100644 --- a/src/libpakfire/parser.c +++ b/src/libpakfire/parser.c @@ -847,20 +847,29 @@ PAKFIRE_EXPORT int pakfire_parser_create_package(PakfireParser parser, } if (is_source) { - PakfireRelationList list; - // Fetch build dependencies char* requires = pakfire_parser_get(parser, "build", "requires"); if (requires && *requires) { - r = pakfire_relationlist_create_from_string(&list, parser->pakfire, requires); - if (r) { - pakfire_relationlist_unref(list); - goto CLEANUP; - } + char* p = requires; + + while (*p) { + char* e = strchr(p, '\n'); - pakfire_package_set_requires(*pkg, list); - pakfire_relationlist_unref(list); + // Terminate the string + if (e) + *e = '\0'; + + // Add the dependency + pakfire_package_add_requires(*pkg, p); + + // End loop when we reached the end + if (!e) + break; + + // Or continue at the next line + p = e + 1; + } } } diff --git a/src/libpakfire/relation.c b/src/libpakfire/relation.c deleted file mode 100644 index 5a166964f..000000000 --- a/src/libpakfire/relation.c +++ /dev/null @@ -1,190 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2013 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -struct _PakfireRelation { - Pakfire pakfire; - Id id; - int nrefs; -}; - -const char* delimiters[] = { - ">=", ">", "<=", "<", "=", NULL, -}; - -static int cmp2type(const char* s) { - if (strcmp(s, ">=") == 0) - return PAKFIRE_GE; - - if (strcmp(s, ">") == 0) - return PAKFIRE_GT; - - if (strcmp(s, "<=") == 0) - return PAKFIRE_LE; - - if (strcmp(s, "<") == 0) - return PAKFIRE_LT; - - if (strcmp(s, "=") == 0) - return PAKFIRE_EQ; - - return 0; -} - -static int cmptype2relflags(int type) { - int flags = 0; - - if (type & PAKFIRE_EQ) - flags |= REL_EQ; - if (type & PAKFIRE_LT) - flags |= REL_LT; - if (type & PAKFIRE_GT) - flags |= REL_GT; - - return flags; -} - -PAKFIRE_EXPORT PakfireRelation pakfire_relation_create(Pakfire pakfire, const char* name, int cmp_type, const char* evr) { - Pool* p = pakfire_get_solv_pool(pakfire); - - Id id = pool_str2id(p, name, 1); - - if (id == STRID_NULL || id == STRID_EMPTY) - return NULL; - - if (evr) { - Id ievr = pool_str2id(p, evr, 1); - int flags = cmptype2relflags(cmp_type); - id = pool_rel2id(p, id, ievr, flags, 1); - } - - return pakfire_relation_create_from_id(pakfire, id); -} - -PAKFIRE_EXPORT PakfireRelation pakfire_relation_create_from_id(Pakfire pakfire, Id id) { - PakfireRelation relation = calloc(1, sizeof(*relation)); - if (relation) { - DEBUG(pakfire, "Allocated Relation at %p\n", relation); - relation->nrefs = 1; - - relation->pakfire = pakfire_ref(pakfire); - relation->id = id; - } - - return relation; -} - -PAKFIRE_EXPORT PakfireRelation pakfire_relation_create_from_string(Pakfire pakfire, const char* s) { - DEBUG(pakfire, "Parsing relation from string: %s\n", s); - - char* name; - char* evr; - - const char** delim = delimiters; - while (*delim) { - pakfire_string_partition(s, *delim, &name, &evr); - - // Nothing to do for no match - if (!name && !evr) { - delim++; - continue; - } - - // Create new relation object - PakfireRelation rel = pakfire_relation_create(pakfire, name, cmp2type(*delim), evr); - - // Cleanup - free(name); - free(evr); - - return rel; - } - - // No delimiter was found - return pakfire_relation_create(pakfire, s, 0, NULL); -} - -PAKFIRE_EXPORT PakfireRelation pakfire_relation_ref(PakfireRelation relation) { - relation->nrefs++; - - return relation; -} - -static void pakfire_relation_free(PakfireRelation relation) { - DEBUG(relation->pakfire, "Releasing Relation at %p\n", relation); - - pakfire_unref(relation->pakfire); - free(relation); -} - -PAKFIRE_EXPORT PakfireRelation pakfire_relation_unref(PakfireRelation relation) { - if (!relation) - return NULL; - - if (--relation->nrefs > 0) - return relation; - - pakfire_relation_free(relation); - return NULL; -} - -PAKFIRE_EXPORT Id pakfire_relation_get_id(PakfireRelation relation) { - return relation->id; -} - -PAKFIRE_EXPORT char* pakfire_relation_str(PakfireRelation relation) { - Pool* pool = pakfire_get_solv_pool(relation->pakfire); - - const char* str = pool_dep2str(pool, relation->id); - - return strdup(str); -} - -PAKFIRE_EXPORT int pakfire_relation2queue(const PakfireRelation relation, Queue* queue, int solver_action) { - queue_push2(queue, SOLVER_SOLVABLE_PROVIDES|solver_action, relation->id); - - return 0; -} - -PAKFIRE_EXPORT PakfirePackageList pakfire_relation_providers(PakfireRelation relation) { - Queue q; - queue_init(&q); - - pakfire_relation2queue(relation, &q, 0); - - PakfirePackageList list = pakfire_packagelist_from_queue(relation->pakfire, &q); - - queue_free(&q); - - return list; -} diff --git a/src/libpakfire/relationlist.c b/src/libpakfire/relationlist.c deleted file mode 100644 index af8f004ec..000000000 --- a/src/libpakfire/relationlist.c +++ /dev/null @@ -1,154 +0,0 @@ -/*############################################################################# -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2013 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -#############################################################################*/ - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -struct _PakfireRelationList { - Pakfire pakfire; - Queue queue; - int nrefs; -}; - -PAKFIRE_EXPORT int pakfire_relationlist_create(PakfireRelationList* list, Pakfire pakfire) { - PakfireRelationList l = calloc(1, sizeof(*l)); - if (!l) - return ENOMEM; - - DEBUG(pakfire, "Allocated RelationList at %p\n", l); - l->pakfire = pakfire_ref(pakfire); - l->nrefs = 1; - - queue_init(&l->queue); - - *list = l; - return 0; -} - -PAKFIRE_EXPORT int pakfire_relationlist_create_from_string(PakfireRelationList* list, Pakfire pakfire, const char* s) { - int r = pakfire_relationlist_create(list, pakfire); - if (r) - return r; - - // Split input by newline - char** elements = pakfire_split_string(s, '\n'); - if (!elements) - return 1; - - for (char** element = elements; *element; element++) { - PakfireRelation rel = pakfire_relation_create_from_string(pakfire, *element); - if (rel) { - pakfire_relationlist_add(*list, rel); - pakfire_relation_unref(rel); - } - - free(*element); - } - - free(elements); - - return 0; -} - -PAKFIRE_EXPORT PakfireRelationList pakfire_relationlist_ref(PakfireRelationList relationlist) { - relationlist->nrefs++; - - return relationlist; -} - -static void pakfire_relationlist_free(PakfireRelationList relationlist) { - DEBUG(relationlist->pakfire, "Releasing RelationList at %p\n", relationlist); - pakfire_unref(relationlist->pakfire); - - queue_free(&relationlist->queue); - free(relationlist); -} - -PAKFIRE_EXPORT PakfireRelationList pakfire_relationlist_unref(PakfireRelationList relationlist) { - if (!relationlist) - return NULL; - - if (--relationlist->nrefs > 0) - return relationlist; - - pakfire_relationlist_free(relationlist); - return NULL; -} - -PAKFIRE_EXPORT void pakfire_relationlist_add(PakfireRelationList relationlist, PakfireRelation relation) { - queue_push(&relationlist->queue, pakfire_relation_get_id(relation)); -} - -PAKFIRE_EXPORT size_t pakfire_relationlist_size(PakfireRelationList relationlist) { - return relationlist->queue.count; -} - -PAKFIRE_EXPORT int pakfire_relationlist_from_queue(PakfireRelationList* list, Pakfire pakfire, Queue q) { - int r = pakfire_relationlist_create(list, pakfire); - if (r) - return r; - - // Release old queue - queue_free(&(*list)->queue); - - // Copy the queue - queue_init_clone(&(*list)->queue, &q); - - return 0; -} - -PAKFIRE_EXPORT PakfireRelation pakfire_relationlist_get(PakfireRelationList relationlist, int index) { - if (index >= relationlist->queue.count) - return NULL; - - Id id = relationlist->queue.elements[index]; - - return pakfire_relation_create_from_id(relationlist->pakfire, id); -} - -Queue* pakfire_relationlist_get_queue(PakfireRelationList list) { - return &list->queue; -} - -static int __sort(const void* _rel1, const void* _rel2, void* _pool) { - const char* s1 = pool_dep2str((Pool*)_pool, *(Id*)_rel1); - const char* s2 = pool_dep2str((Pool*)_pool, *(Id*)_rel2); - - return strcmp(s1, s2); -} - -PAKFIRE_EXPORT void pakfire_relationlist_sort(PakfireRelationList list) { - Pool* pool = pakfire_get_solv_pool(list->pakfire); - - qsort_r(list->queue.elements, list->queue.count, sizeof(*list->queue.elements), - __sort, pool); -}