From: Michael Tremer Date: Tue, 25 Oct 2022 15:42:49 +0000 (+0000) Subject: packages: Drop old property functions for strings X-Git-Tag: 0.9.28~221 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=74468e4fc2585892a40a2b7b3bfb69c21c8fe3f8;p=pakfire.git packages: Drop old property functions for strings Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/package.c b/src/_pakfire/package.c index a81c3f867..1141de0f6 100644 --- a/src/_pakfire/package.c +++ b/src/_pakfire/package.c @@ -77,13 +77,13 @@ static int Package_init(PackageObject* self, PyObject* args, PyObject* kwds) { } static PyObject* Package_repr(PackageObject* self) { - const char* nevra = pakfire_package_get_nevra(self->package); + const char* nevra = pakfire_package_get_string(self->package, PAKFIRE_PKG_NEVRA); return PyUnicode_FromFormat("<_pakfire.Package %s>", nevra); } static PyObject* Package_str(PackageObject* self) { - const char* nevra = pakfire_package_get_nevra(self->package); + const char* nevra = pakfire_package_get_string(self->package, PAKFIRE_PKG_NEVRA); return PyUnicode_FromString(nevra); } @@ -145,21 +145,15 @@ static const char* PyUnicode_FromValue(PyObject* value) { } static PyObject* Package_get_name(PackageObject* self) { - const char* name = pakfire_package_get_name(self->package); + const char* name = pakfire_package_get_string(self->package, PAKFIRE_PKG_NAME); if (!name) Py_RETURN_NONE; return PyUnicode_FromString(name); } -static void Package_set_name(PackageObject* self, PyObject* value) { - const char* name = PyUnicode_FromValue(value); - - pakfire_package_set_name(self->package, name); -} - static PyObject* Package_get_evr(PackageObject* self) { - const char* evr = pakfire_package_get_evr(self->package); + const char* evr = pakfire_package_get_string(self->package, PAKFIRE_PKG_EVR); if (!evr) Py_RETURN_NONE; @@ -167,21 +161,15 @@ static PyObject* Package_get_evr(PackageObject* self) { } static PyObject* Package_get_arch(PackageObject* self) { - const char* arch = pakfire_package_get_arch(self->package); + const char* arch = pakfire_package_get_string(self->package, PAKFIRE_PKG_ARCH); if (!arch) Py_RETURN_NONE; return PyUnicode_FromString(arch); } -static void Package_set_arch(PackageObject* self, PyObject* value) { - const char* arch = PyUnicode_FromValue(value); - - pakfire_package_set_arch(self->package, arch); -} - static PyObject* Package_get_uuid(PackageObject* self) { - const char* uuid = pakfire_package_get_uuid(self->package); + const char* uuid = pakfire_package_get_string(self->package, PAKFIRE_PKG_UUID); if (!uuid) Py_RETURN_NONE; @@ -191,7 +179,7 @@ static PyObject* Package_get_uuid(PackageObject* self) { static void Package_set_uuid(PackageObject* self, PyObject* value) { const char* uuid = PyUnicode_FromValue(value); - pakfire_package_set_uuid(self->package, uuid); + pakfire_package_set_string(self->package, PAKFIRE_PKG_UUID, uuid); } static PyObject* Package_get_digest(PackageObject* self) { @@ -208,7 +196,7 @@ static PyObject* Package_get_digest(PackageObject* self) { } static PyObject* Package_get_summary(PackageObject* self) { - const char* summary = pakfire_package_get_summary(self->package); + const char* summary = pakfire_package_get_string(self->package, PAKFIRE_PKG_SUMMARY); if (!summary) Py_RETURN_NONE; @@ -218,11 +206,11 @@ static PyObject* Package_get_summary(PackageObject* self) { static void Package_set_summary(PackageObject* self, PyObject* value) { const char* summary = PyUnicode_FromValue(value); - pakfire_package_set_summary(self->package, summary); + pakfire_package_set_string(self->package, PAKFIRE_PKG_SUMMARY, summary); } static PyObject* Package_get_description(PackageObject* self) { - const char* description = pakfire_package_get_description(self->package); + const char* description = pakfire_package_get_string(self->package, PAKFIRE_PKG_DESCRIPTION); if (!description) Py_RETURN_NONE; @@ -232,11 +220,11 @@ static PyObject* Package_get_description(PackageObject* self) { static void Package_set_description(PackageObject* self, PyObject* value) { const char* description = PyUnicode_FromValue(value); - pakfire_package_set_description(self->package, description); + pakfire_package_set_string(self->package, PAKFIRE_PKG_DESCRIPTION, description); } static PyObject* Package_get_license(PackageObject* self) { - const char* license = pakfire_package_get_license(self->package); + const char* license = pakfire_package_get_string(self->package, PAKFIRE_PKG_LICENSE); if (!license) Py_RETURN_NONE; @@ -246,11 +234,11 @@ static PyObject* Package_get_license(PackageObject* self) { static void Package_set_license(PackageObject* self, PyObject* value) { const char* license = PyUnicode_FromValue(value); - pakfire_package_set_summary(self->package, license); + pakfire_package_set_string(self->package, PAKFIRE_PKG_LICENSE, license); } static PyObject* Package_get_url(PackageObject* self) { - const char* url = pakfire_package_get_url(self->package); + const char* url = pakfire_package_get_string(self->package, PAKFIRE_PKG_URL); if (!url) Py_RETURN_NONE; @@ -260,11 +248,11 @@ static PyObject* Package_get_url(PackageObject* self) { static void Package_set_url(PackageObject* self, PyObject* value) { const char* url = PyUnicode_FromValue(value); - pakfire_package_set_url(self->package, url); + pakfire_package_set_string(self->package, PAKFIRE_PKG_URL, url); } static PyObject* Package_get_groups(PackageObject* self) { - const char* s = pakfire_package_get_groups(self->package); + const char* s = pakfire_package_get_string(self->package, PAKFIRE_PKG_GROUPS); return PyUnicode_FromString(s); } @@ -273,13 +261,13 @@ static int Package_set_groups(PackageObject* self, PyObject* value) { const char* groups = PyUnicode_AsUTF8(value); if (groups) - pakfire_package_set_groups(self->package, groups); + pakfire_package_set_string(self->package, PAKFIRE_PKG_GROUPS, groups); return 0; } static PyObject* Package_get_vendor(PackageObject* self) { - const char* vendor = pakfire_package_get_vendor(self->package); + const char* vendor = pakfire_package_get_string(self->package, PAKFIRE_PKG_VENDOR); if (!vendor) Py_RETURN_NONE; @@ -289,11 +277,11 @@ static PyObject* Package_get_vendor(PackageObject* self) { static void Package_set_vendor(PackageObject* self, PyObject* value) { const char* vendor = PyUnicode_FromValue(value); - pakfire_package_set_vendor(self->package, vendor); + pakfire_package_set_string(self->package, PAKFIRE_PKG_VENDOR, vendor); } static PyObject* Package_get_distribution(PackageObject* self) { - const char* distribution = pakfire_package_get_distribution(self->package); + const char* distribution = pakfire_package_get_string(self->package, PAKFIRE_PKG_DISTRO); if (!distribution) Py_RETURN_NONE; @@ -303,11 +291,11 @@ static PyObject* Package_get_distribution(PackageObject* self) { static void Package_set_distribution(PackageObject* self, PyObject* value) { const char* distribution = PyUnicode_AsUTF8(value); - pakfire_package_set_distribution(self->package, distribution); + pakfire_package_set_string(self->package, PAKFIRE_PKG_DISTRO, distribution); } static PyObject* Package_get_maintainer(PackageObject* self) { - const char* maintainer = pakfire_package_get_maintainer(self->package); + const char* maintainer = pakfire_package_get_string(self->package, PAKFIRE_PKG_MAINTAINER); if (!maintainer) Py_RETURN_NONE; @@ -317,7 +305,7 @@ static PyObject* Package_get_maintainer(PackageObject* self) { static void Package_set_maintainer(PackageObject* self, PyObject* value) { const char* maintainer = PyUnicode_FromValue(value); - pakfire_package_set_maintainer(self->package, maintainer); + pakfire_package_set_string(self->package, PAKFIRE_PKG_MAINTAINER, maintainer); } static PyObject* Package_get_filename(PackageObject* self) { @@ -728,7 +716,7 @@ static struct PyGetSetDef Package_getsetters[] = { { "name", (getter)Package_get_name, - (setter)Package_set_name, + NULL, NULL, NULL }, @@ -742,7 +730,7 @@ static struct PyGetSetDef Package_getsetters[] = { { "arch", (getter)Package_get_arch, - (setter)Package_set_arch, + NULL, NULL, NULL }, diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index 9841e0f37..9b39bdf08 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -859,7 +859,7 @@ static int __pakfire_archive_extract(struct pakfire_archive* archive, int flags) goto ERROR; // Fetch NEVRA - const char* nevra = pakfire_package_get_nevra(pkg); + const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA); DEBUG(archive->pakfire, "Extracting %s\n", archive->path); @@ -1066,7 +1066,8 @@ static int pakfire_archive_make_package_from_json(struct pakfire_archive* archiv return 1; #ifdef ENABLE_DEBUG - const char* nevra = pakfire_package_get_nevra(pkg); + const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA); + DEBUG(archive->pakfire, "Created package %s (%p) from archive %p\n", nevra, pkg, archive); #endif @@ -1093,48 +1094,75 @@ static int pakfire_archive_make_package_from_json(struct pakfire_archive* archiv // Vendor const char* vendor = pakfire_archive_metadata_get(archive, "vendor", NULL); - if (vendor) - pakfire_package_set_vendor(pkg, vendor); + if (vendor) { + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_VENDOR, vendor); + if (r) + goto ERROR; + } // UUID const char* uuid = pakfire_archive_metadata_get(archive, "uuid", NULL); - if (uuid) - pakfire_package_set_uuid(pkg, uuid); + if (uuid) { + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_UUID, uuid); + if (r) + goto ERROR; + } // Groups const char* groups = pakfire_archive_metadata_get(archive, "groups", NULL); - if (groups) - pakfire_package_set_groups(pkg, groups); + if (groups) { + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_GROUPS, groups); + if (r) + goto ERROR; + } // Distribution const char* distro = pakfire_archive_metadata_get(archive, "distribution", NULL); - if (distro) - pakfire_package_set_distribution(pkg, distro); + if (distro) { + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_DISTRO, distro); + if (r) + goto ERROR; + } // Maintainer const char* maintainer = pakfire_archive_metadata_get(archive, "maintainer", NULL); - if (maintainer) - pakfire_package_set_maintainer(pkg, maintainer); + if (maintainer) { + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_MAINTAINER, maintainer); + if (r) + goto ERROR; + } // URL const char* url = pakfire_archive_metadata_get(archive, "url", NULL); - if (url) - pakfire_package_set_url(pkg, url); + if (url) { + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_URL, url); + if (r) + goto ERROR; + } // License const char* license = pakfire_archive_metadata_get(archive, "license", NULL); - if (license) - pakfire_package_set_license(pkg, license); + if (license) { + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_LICENSE, license); + if (r) + goto ERROR; + } // Summary const char* summary = pakfire_archive_metadata_get(archive, "summary", NULL); - if (summary) - pakfire_package_set_summary(pkg, summary); + if (summary) { + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_SUMMARY, summary); + if (r) + goto ERROR; + } // Description const char* description = pakfire_archive_metadata_get(archive, "description", NULL); - if (description) - pakfire_package_set_description(pkg, description); + if (description) { + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_DESCRIPTION, description); + if (r) + goto ERROR; + } // Installed package size size_t installsize = pakfire_archive_metadata_get_int64(archive, "size", NULL); @@ -1238,6 +1266,24 @@ ERROR: return r; } +static int pakfire_archive_package_set_string(struct pakfire_archive* archive, + struct pakfire_package* pkg, const enum pakfire_package_key key, + const char* key1, const char* key2) { + char* value = NULL; + int r; + + // Fetch the value + value = pakfire_archive_get(archive, key1, key2); + + // Set the value + r = pakfire_package_set_string(pkg, key, value); + + if (value) + free(value); + + return r; +} + static int pakfire_archive_make_legacy_package(struct pakfire_archive* archive, struct pakfire_repo* repo, struct pakfire_package** package) { int r; @@ -1297,7 +1343,8 @@ static int pakfire_archive_make_legacy_package(struct pakfire_archive* archive, *package = pkg; #ifdef ENABLE_DEBUG - const char* nevra = pakfire_package_get_nevra(pkg); + const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA); + DEBUG(archive->pakfire, "Created package %s (%p) from archive %p\n", nevra, pkg, archive); #endif @@ -1306,53 +1353,46 @@ static int pakfire_archive_make_legacy_package(struct pakfire_archive* archive, pakfire_package_set_path(pkg, archive->path); // Set UUID - char* uuid = pakfire_archive_get(archive, "package", "uuid"); - if (uuid) { - pakfire_package_set_uuid(pkg, uuid); - free(uuid); - } + r = pakfire_archive_package_set_string(archive, pkg, + PAKFIRE_PKG_UUID, "package", "uuid"); + if (r) + goto ERROR; // Set groups - char* groups = pakfire_archive_get(archive, "package", "groups"); - if (groups) { - pakfire_package_set_groups(pkg, groups); - free(groups); - } + r = pakfire_archive_package_set_string(archive, pkg, + PAKFIRE_PKG_GROUPS, "package", "groups"); + if (r) + goto ERROR; // Set maintainer - char* maintainer = pakfire_archive_get(archive, "package", "maintainer"); - if (maintainer) { - pakfire_package_set_maintainer(pkg, maintainer); - free(maintainer); - } + r = pakfire_archive_package_set_string(archive, pkg, + PAKFIRE_PKG_MAINTAINER, "package", "maintainer"); + if (r) + goto ERROR; // Set URL - char* url = pakfire_archive_get(archive, "package", "url"); - if (url) { - pakfire_package_set_url(pkg, url); - free(url); - } + r = pakfire_archive_package_set_string(archive, pkg, + PAKFIRE_PKG_URL, "package", "url"); + if (r) + goto ERROR; // Set license - char* license = pakfire_archive_get(archive, "package", "license"); - if (license) { - pakfire_package_set_license(pkg, license); - free(license); - } + r = pakfire_archive_package_set_string(archive, pkg, + PAKFIRE_PKG_LICENSE, "package", "license"); + if (r) + goto ERROR; // Set summary - char* summary = pakfire_archive_get(archive, "package", "summary"); - if (summary) { - pakfire_package_set_summary(pkg, summary); - free(summary); - } + r = pakfire_archive_package_set_string(archive, pkg, + PAKFIRE_PKG_SUMMARY, "package", "summary"); + if (r) + goto ERROR; // Set description - char* description = pakfire_archive_get(archive, "package", "description"); - if (description) { - pakfire_package_set_description(pkg, description); - free(description); - } + r = pakfire_archive_package_set_string(archive, pkg, + PAKFIRE_PKG_DESCRIPTION, "package", "description"); + if (r) + goto ERROR; // Get package size pakfire_package_set_downloadsize(pkg, pakfire_archive_get_size(archive)); @@ -1367,11 +1407,10 @@ static int pakfire_archive_make_legacy_package(struct pakfire_archive* archive, } // Set vendor - char* vendor = pakfire_archive_get(archive, "distribution", "vendor"); - if (vendor) { - pakfire_package_set_vendor(pkg, vendor); - free(vendor); - } + r = pakfire_archive_package_set_string(archive, pkg, + PAKFIRE_PKG_VENDOR, "distribution", "vendor"); + if (r) + goto ERROR; // Set build host char* build_host = pakfire_archive_get(archive, "build", "host"); @@ -1445,7 +1484,8 @@ static int pakfire_archive_make_legacy_package(struct pakfire_archive* archive, break; } - return 0; +ERROR: + return r; } /* diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 98712f5de..7eb353740 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -536,8 +536,11 @@ static int pakfire_build_package(struct pakfire_build* build, struct pakfire_par // Set distribution const char* distribution = pakfire_parser_get(makefile, NULL, "DISTRO_NAME"); - if (distribution) - pakfire_package_set_distribution(pkg, distribution); + if (distribution) { + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_DISTRO, distribution); + if (r) + goto ERROR; + } // Set build ID pakfire_package_set_build_id_from_uuid(pkg, &build->id); @@ -1154,8 +1157,8 @@ static int pakfire_build_read_makefile(struct pakfire_build* build, struct pakfire_parser_error* error = NULL; - const char* nevra = pakfire_package_get_nevra(package); - const char* name = pakfire_package_get_name(package); + const char* nevra = pakfire_package_get_string(package, PAKFIRE_PKG_NEVRA); + const char* name = pakfire_package_get_string(package, PAKFIRE_PKG_NAME); // Compose path to makefile r = pakfire_path(build->pakfire, path, "/usr/src/packages/%s/%s.nm", nevra, name); @@ -1309,7 +1312,7 @@ PAKFIRE_EXPORT int pakfire_build_exec(struct pakfire_build* build, const char* p goto ERROR; } - const char* nevra = pakfire_package_get_nevra(package); + const char* nevra = pakfire_package_get_string(package, PAKFIRE_PKG_NEVRA); INFO(build->pakfire, "Building %s...\n", nevra); diff --git a/src/libpakfire/db.c b/src/libpakfire/db.c index f05d48624..fa5214416 100644 --- a/src/libpakfire/db.c +++ b/src/libpakfire/db.c @@ -1321,7 +1321,7 @@ int pakfire_db_add_package(struct pakfire_db* db, } // Bind name - const char* name = pakfire_package_get_name(pkg); + const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME); r = sqlite3_bind_text(stmt, 1, name, -1, NULL); if (r) { @@ -1330,7 +1330,7 @@ int pakfire_db_add_package(struct pakfire_db* db, } // Bind evr - const char* evr = pakfire_package_get_evr(pkg); + const char* evr = pakfire_package_get_string(pkg, PAKFIRE_PKG_EVR); r = sqlite3_bind_text(stmt, 2, evr, -1, NULL); if (r) { @@ -1339,7 +1339,7 @@ int pakfire_db_add_package(struct pakfire_db* db, } // Bind arch - const char* arch = pakfire_package_get_arch(pkg); + const char* arch = pakfire_package_get_string(pkg, PAKFIRE_PKG_ARCH); r = sqlite3_bind_text(stmt, 3, arch, -1, NULL); if (r) { @@ -1348,17 +1348,15 @@ int pakfire_db_add_package(struct pakfire_db* db, } // Bind groups - char* groups = pakfire_package_get_groups(pkg); + const char* groups = pakfire_package_get_string(pkg, PAKFIRE_PKG_GROUPS); + if (groups) { r = sqlite3_bind_text(stmt, 4, groups, -1, NULL); if (r) { ERROR(db->pakfire, "Could not bind groups: %s\n", sqlite3_errmsg(db->handle)); - free(groups); goto ERROR; } - free(groups); - // No groups } else { r = sqlite3_bind_null(stmt, 4); @@ -1420,7 +1418,7 @@ int pakfire_db_add_package(struct pakfire_db* db, } // Bind license - const char* license = pakfire_package_get_license(pkg); + const char* license = pakfire_package_get_string(pkg, PAKFIRE_PKG_LICENSE); r = sqlite3_bind_text(stmt, 10, license, -1, NULL); if (r) { @@ -1429,7 +1427,7 @@ int pakfire_db_add_package(struct pakfire_db* db, } // Bind summary - const char* summary = pakfire_package_get_summary(pkg); + const char* summary = pakfire_package_get_string(pkg, PAKFIRE_PKG_SUMMARY); r = sqlite3_bind_text(stmt, 11, summary, -1, NULL); if (r) { @@ -1438,7 +1436,7 @@ int pakfire_db_add_package(struct pakfire_db* db, } // Bind description - const char* description = pakfire_package_get_description(pkg); + const char* description = pakfire_package_get_string(pkg, PAKFIRE_PKG_DESCRIPTION); r = sqlite3_bind_text(stmt, 12, description, -1, NULL); if (r) { @@ -1447,7 +1445,7 @@ int pakfire_db_add_package(struct pakfire_db* db, } // Bind uuid - const char* uuid = pakfire_package_get_uuid(pkg); + const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID); r = sqlite3_bind_text(stmt, 13, uuid, -1, NULL); if (r) { @@ -1456,7 +1454,7 @@ int pakfire_db_add_package(struct pakfire_db* db, } // Bind vendor - const char* vendor = pakfire_package_get_vendor(pkg); + const char* vendor = pakfire_package_get_string(pkg, PAKFIRE_PKG_VENDOR); r = sqlite3_bind_text(stmt, 14, vendor, -1, NULL); if (r) { @@ -1543,7 +1541,7 @@ int pakfire_db_add_package(struct pakfire_db* db, } // Distribution - const char* distribution = pakfire_package_get_distribution(pkg); + const char* distribution = pakfire_package_get_string(pkg, PAKFIRE_PKG_DISTRO); if (distribution) { r = sqlite3_bind_text(stmt, 22, distribution, -1, NULL); if (r) @@ -1607,7 +1605,7 @@ int pakfire_db_remove_package(struct pakfire_db* db, struct pakfire_package* pkg goto ERROR; // Fetch the package's UUID - const char* uuid = pakfire_package_get_uuid(pkg); + const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID); if (!uuid) { ERROR(db->pakfire, "Package has no UUID\n"); r = 1; @@ -1664,7 +1662,7 @@ struct pakfire_scriptlet* pakfire_db_get_scriptlet(struct pakfire_db* db, int r = 1; // Fetch the package's UUID - const char* uuid = pakfire_package_get_uuid(pkg); + const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID); if (!uuid) { ERROR(db->pakfire, "Package has no UUID\n"); goto ERROR; @@ -1759,7 +1757,9 @@ static int pakfire_db_load_package(struct pakfire_db* db, struct pakfire_repo* r // Groups const char* groups = (const char*)sqlite3_column_text(stmt, 4); if (groups) { - pakfire_package_set_groups(pkg, groups); + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_GROUPS, groups); + if (r) + goto ERROR; } // Filename @@ -1795,31 +1795,41 @@ static int pakfire_db_load_package(struct pakfire_db* db, struct pakfire_repo* r // License const char* license = (const char*)sqlite3_column_text(stmt, 10); if (license) { - pakfire_package_set_license(pkg, license); + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_LICENSE, license); + if (r) + goto ERROR; } // Summary const char* summary = (const char*)sqlite3_column_text(stmt, 11); if (summary) { - pakfire_package_set_summary(pkg, summary); + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_SUMMARY, summary); + if (r) + goto ERROR; } // Description const char* description = (const char*)sqlite3_column_text(stmt, 12); if (description) { - pakfire_package_set_description(pkg, description); + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_DESCRIPTION, description); + if (r) + goto ERROR; } // UUID const char* uuid = (const char*)sqlite3_column_text(stmt, 13); if (uuid) { - pakfire_package_set_uuid(pkg, uuid); + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_UUID, uuid); + if (r) + goto ERROR; } // Vendor const char* vendor = (const char*)sqlite3_column_text(stmt, 14); if (vendor) { - pakfire_package_set_vendor(pkg, vendor); + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_VENDOR, vendor); + if (r) + goto ERROR; } // Build Host @@ -1895,8 +1905,11 @@ static int pakfire_db_load_package(struct pakfire_db* db, struct pakfire_repo* r // Distribution const char* distribution = (const char*)sqlite3_column_text(stmt, 32); - if (distribution) - pakfire_package_set_distribution(pkg, distribution); + if (distribution) { + r = pakfire_package_set_string(pkg, PAKFIRE_PKG_DESCRIPTION, description); + if (r) + goto ERROR; + } // Success r = 0; diff --git a/src/libpakfire/dist.c b/src/libpakfire/dist.c index b93e88607..4bb4729ef 100644 --- a/src/libpakfire/dist.c +++ b/src/libpakfire/dist.c @@ -259,7 +259,7 @@ static int pakfire_dist_add_source(struct pakfire* pakfire, struct pakfire_packa char archive_path[PATH_MAX]; char cache_path[PATH_MAX]; - const char* name = pakfire_package_get_name(pkg); + const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME); // Compose path r = pakfire_cache_path(pakfire, cache_path, "sources/%s/%s", name, filename); diff --git a/src/libpakfire/include/pakfire/package.h b/src/libpakfire/include/pakfire/package.h index 83d13f953..43d35cb5b 100644 --- a/src/libpakfire/include/pakfire/package.h +++ b/src/libpakfire/include/pakfire/package.h @@ -58,41 +58,15 @@ int pakfire_package_eq(struct pakfire_package* pkg1, struct pakfire_package* pkg int pakfire_package_cmp(struct pakfire_package* pkg1, struct pakfire_package* pkg2); int pakfire_package_evr_cmp(struct pakfire_package* pkg1, struct pakfire_package* pkg2); -const char* pakfire_package_get_nevra(struct pakfire_package* pkg); -const char* pakfire_package_get_name(struct pakfire_package* pkg); -void pakfire_package_set_name(struct pakfire_package* pkg, const char* name); -const char* pakfire_package_get_evr(struct pakfire_package* pkg); -void pakfire_package_set_evr(struct pakfire_package* pkg, const char* evr); -const char* pakfire_package_get_arch(struct pakfire_package* pkg); -void pakfire_package_set_arch(struct pakfire_package* pkg, const char* arch); - const char* pakfire_package_get_string(struct pakfire_package* pkg, const enum pakfire_package_key key); int pakfire_package_set_string(struct pakfire_package* pkg, const enum pakfire_package_key key, const char* value); -const char* pakfire_package_get_uuid(struct pakfire_package* pkg); -void pakfire_package_set_uuid(struct pakfire_package* pkg, const char* uuid); const unsigned char* pakfire_package_get_digest(struct pakfire_package* pkg, enum pakfire_digest_types* type, size_t* length); int pakfire_package_set_digest(struct pakfire_package* pkg, enum pakfire_digest_types type, const unsigned char* digest, const size_t length); -const char* pakfire_package_get_summary(struct pakfire_package* pkg); -void pakfire_package_set_summary(struct pakfire_package* pkg, const char* summary); -const char* pakfire_package_get_description(struct pakfire_package* pkg); -void pakfire_package_set_description(struct pakfire_package* pkg, const char* description); -const char* pakfire_package_get_license(struct pakfire_package* pkg); -void pakfire_package_set_license(struct pakfire_package* pkg, const char* license); -const char* pakfire_package_get_url(struct pakfire_package* pkg); -void pakfire_package_set_url(struct pakfire_package* pkg, const char* url); -char* pakfire_package_get_groups(struct pakfire_package* pkg); -void pakfire_package_set_groups(struct pakfire_package* pkg, const char* groups); -const char* pakfire_package_get_vendor(struct pakfire_package* pkg); -void pakfire_package_set_vendor(struct pakfire_package* pkg, const char* vendor); -const char* pakfire_package_get_distribution(struct pakfire_package* pkg); -void pakfire_package_set_distribution(struct pakfire_package* pkg, const char* distribution); -const char* pakfire_package_get_maintainer(struct pakfire_package* pkg); -void pakfire_package_set_maintainer(struct pakfire_package* pkg, const char* maintainer); const char* pakfire_package_get_filename(struct pakfire_package* pkg); const char* pakfire_package_get_path(struct pakfire_package* pkg); void pakfire_package_set_path(struct pakfire_package* pkg, const char* path); diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index edb3e2067..d1bf206ae 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -167,28 +167,19 @@ global: pakfire_package_create; pakfire_package_dump; pakfire_package_eq; - pakfire_package_get_arch; pakfire_package_get_build_host; pakfire_package_get_build_id; pakfire_package_get_build_time; pakfire_package_get_cache_path; pakfire_package_get_conflicts; - pakfire_package_get_description; pakfire_package_get_digest; - pakfire_package_get_distribution; pakfire_package_get_downloadsize; pakfire_package_get_enhances; - pakfire_package_get_evr; pakfire_package_get_filelist; pakfire_package_get_filename; - pakfire_package_get_groups; - pakfire_package_get_license; pakfire_package_get_location; pakfire_package_get_installsize; pakfire_package_get_install_time; - pakfire_package_get_maintainer; - pakfire_package_get_name; - pakfire_package_get_nevra; pakfire_package_get_obsoletes; pakfire_package_get_pakfire; pakfire_package_get_path; @@ -205,39 +196,23 @@ global: pakfire_package_get_source_package; pakfire_package_get_string; pakfire_package_get_suggests; - pakfire_package_get_summary; pakfire_package_get_supplements; - pakfire_package_get_url; - pakfire_package_get_uuid; - pakfire_package_get_vendor; pakfire_package_is_installed; pakfire_package_ref; - pakfire_package_set_arch; pakfire_package_set_build_host; pakfire_package_set_build_id; pakfire_package_set_build_time; pakfire_package_set_checksum; - pakfire_package_set_description; - pakfire_package_set_distribution; pakfire_package_set_downloadsize; - pakfire_package_set_evr; pakfire_package_set_filelist; pakfire_package_set_filename; - pakfire_package_set_groups; pakfire_package_set_installsize; pakfire_package_set_install_time; - pakfire_package_set_license; - pakfire_package_set_maintainer; - pakfire_package_set_name; pakfire_package_set_path; pakfire_package_set_source_arch; pakfire_package_set_source_evr; pakfire_package_set_source_name; pakfire_package_set_string; - pakfire_package_set_summary; - pakfire_package_set_url; - pakfire_package_set_uuid; - pakfire_package_set_vendor; pakfire_package_unref; # packagelist diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 0e376fb9d..d1a4bb5f7 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -106,9 +106,9 @@ PAKFIRE_EXPORT struct pakfire_package* pakfire_package_create( pkg->repo = pakfire_repo_ref(repo); // Set the given attributes - pakfire_package_set_name(pkg, name); - pakfire_package_set_evr(pkg, evr); - pakfire_package_set_arch(pkg, arch); + pakfire_package_set_string(pkg, PAKFIRE_PKG_NAME, name); + pakfire_package_set_string(pkg, PAKFIRE_PKG_EVR, evr); + pakfire_package_set_string(pkg, PAKFIRE_PKG_ARCH, arch); ERROR: if (dummy) @@ -206,49 +206,6 @@ Id pakfire_package_id(struct pakfire_package* pkg) { return pkg->id; } -PAKFIRE_EXPORT const char* pakfire_package_get_nevra(struct pakfire_package* pkg) { - if (!*pkg->nevra) { - Pool* pool = pakfire_get_solv_pool(pkg->pakfire); - Solvable* s = get_solvable(pkg); - - pakfire_string_set(pkg->nevra, pool_solvable2str(pool, s)); - } - - return pkg->nevra; -} - -PAKFIRE_EXPORT const char* pakfire_package_get_name(struct pakfire_package* pkg) { - Pool* pool = pakfire_get_solv_pool(pkg->pakfire); - Solvable* s = get_solvable(pkg); - - return pool_id2str(pool, s->name); -} - -PAKFIRE_EXPORT void pakfire_package_set_name(struct pakfire_package* pkg, const char* name) { - Pool* pool = pakfire_get_solv_pool(pkg->pakfire); - Solvable* s = get_solvable(pkg); - - s->name = pool_str2id(pool, name, 1); -} - -PAKFIRE_EXPORT const char* pakfire_package_get_evr(struct pakfire_package* pkg) { - Pool* pool = pakfire_get_solv_pool(pkg->pakfire); - Solvable* s = get_solvable(pkg); - - return pool_id2str(pool, s->evr); -} - -PAKFIRE_EXPORT void pakfire_package_set_evr(struct pakfire_package* pkg, const char* evr) { - Pool* pool = pakfire_get_solv_pool(pkg->pakfire); - Solvable* s = get_solvable(pkg); - - // Skip empty epoch - if (pakfire_string_startswith(evr, "0:")) - evr += 2; - - s->evr = pool_str2id(pool, evr, 1); -} - char* pakfire_package_join_evr(const char* e, const char* v, const char* r) { char* buffer = NULL; @@ -276,22 +233,8 @@ char* pakfire_package_join_evr(const char* e, const char* v, const char* r) { return buffer; } -PAKFIRE_EXPORT const char* pakfire_package_get_arch(struct pakfire_package* pkg) { - Pool* pool = pakfire_get_solv_pool(pkg->pakfire); - Solvable* s = get_solvable(pkg); - - return pool_id2str(pool, s->arch); -} - -PAKFIRE_EXPORT void pakfire_package_set_arch(struct pakfire_package* pkg, const char* arch) { - Pool* pool = pakfire_get_solv_pool(pkg->pakfire); - Solvable* s = get_solvable(pkg); - - s->arch = pool_str2id(pool, arch, 1); -} - int pakfire_package_is_source(struct pakfire_package* pkg) { - const char* arch = pakfire_package_get_arch(pkg); + const char* arch = pakfire_package_get_string(pkg, PAKFIRE_PKG_ARCH); if (!arch) return 1; @@ -383,15 +326,40 @@ PAKFIRE_EXPORT const char* pakfire_package_get_string( return ret; } -int pakfire_package_set_string( +PAKFIRE_EXPORT int pakfire_package_set_string( struct pakfire_package* pkg, const enum pakfire_package_key key, const char* value) { Id id = ID_NULL; + Pool* pool = pakfire_get_solv_pool(pkg->pakfire); + Solvable* s = get_solvable(pkg); + switch (key) { // Do not allow to change name, evr, or arch case PAKFIRE_PKG_NAME: + // Reset nevra & filename + *pkg->nevra = *pkg->filename = '\0'; + + s->name = pool_str2id(pool, value, 1); + return 0; + case PAKFIRE_PKG_EVR: + // Reset nevra & filename + *pkg->nevra = *pkg->filename = '\0'; + + // Skip empty epoch + if (pakfire_string_startswith(value, "0:")) + value += 2; + + s->evr = pool_str2id(pool, value, 1); + return 0; + case PAKFIRE_PKG_ARCH: + // Reset nevra & filename + *pkg->nevra = *pkg->filename = '\0'; + + s->arch = pool_str2id(pool, value, 1); + return 0; + case PAKFIRE_PKG_NEVRA: errno = EINVAL; return 1; @@ -439,8 +407,6 @@ int pakfire_package_set_string( return 1; } - Solvable* s = get_solvable(pkg); - // Unset on empty string if (!value || !*value) solvable_unset(s, id); @@ -467,44 +433,6 @@ static void pakfire_package_set_num(struct pakfire_package* pkg, Id type, unsign solvable_set_num(s, type, value); } -static char** pakfire_package_get_string_array(struct pakfire_package* pkg, Id key) { - char** strings = NULL; - - Queue ids; - queue_init(&ids); - - Pool* pool = pakfire_get_solv_pool(pkg->pakfire); - Solvable* s = get_solvable(pkg); - solvable_lookup_idarray(s, key, &ids); - - if (ids.count > 0) { - strings = calloc(ids.count + 1, sizeof(*strings)); - if (!strings) { - queue_free(&ids); - return NULL; - } - - for (int i = 0; i < ids.count; i++) { - const char* value = pool_id2str(pool, ids.elements[i]); - strings[i] = strdup(value); - } - - strings[ids.count] = NULL; - } - - queue_free(&ids); - - return strings; -} - -static void pakfire_package_add_string_array(struct pakfire_package* pkg, Id key, const char* value) { - if (!value) - return; - - Solvable* s = get_solvable(pkg); - solvable_add_poolstr_array(s, key, value); -} - uint64_t pakfire_package_get_dbid(struct pakfire_package* pkg) { return pakfire_package_get_num(pkg, RPM_RPMDBID); } @@ -513,14 +441,6 @@ void pakfire_package_set_dbid(struct pakfire_package* pkg, uint64_t id) { pakfire_package_set_num(pkg, RPM_RPMDBID, id); } -PAKFIRE_EXPORT const char* pakfire_package_get_uuid(struct pakfire_package* pkg) { - return pakfire_package_get_string(pkg, SOLVABLE_PKGID); -} - -PAKFIRE_EXPORT void pakfire_package_set_uuid(struct pakfire_package* pkg, const char* uuid) { - pakfire_package_set_string(pkg, SOLVABLE_PKGID, uuid); -} - static enum pakfire_digest_types pakfire_package_id2digest(Id id) { switch (id) { case REPOKEY_TYPE_SHA512: @@ -598,90 +518,6 @@ ERROR: return r; } -PAKFIRE_EXPORT const char* pakfire_package_get_summary(struct pakfire_package* pkg) { - return pakfire_package_get_string(pkg, SOLVABLE_SUMMARY); -} - -PAKFIRE_EXPORT void pakfire_package_set_summary(struct pakfire_package* pkg, const char* summary) { - pakfire_package_set_string(pkg, SOLVABLE_SUMMARY, summary); -} - -PAKFIRE_EXPORT const char* pakfire_package_get_description(struct pakfire_package* pkg) { - return pakfire_package_get_string(pkg, SOLVABLE_DESCRIPTION); -} - -PAKFIRE_EXPORT void pakfire_package_set_description(struct pakfire_package* pkg, const char* description) { - pakfire_package_set_string(pkg, SOLVABLE_DESCRIPTION, description); -} - -PAKFIRE_EXPORT const char* pakfire_package_get_license(struct pakfire_package* pkg) { - return pakfire_package_get_string(pkg, SOLVABLE_LICENSE); -} - -PAKFIRE_EXPORT void pakfire_package_set_license(struct pakfire_package* pkg, const char* license) { - pakfire_package_set_string(pkg, SOLVABLE_LICENSE, license); -} - -PAKFIRE_EXPORT const char* pakfire_package_get_url(struct pakfire_package* pkg) { - return pakfire_package_get_string(pkg, SOLVABLE_URL); -} - -PAKFIRE_EXPORT void pakfire_package_set_url(struct pakfire_package* pkg, const char* url) { - pakfire_package_set_string(pkg, SOLVABLE_URL, url); -} - -PAKFIRE_EXPORT char* pakfire_package_get_groups(struct pakfire_package* pkg) { - char** groups = pakfire_package_get_string_array(pkg, SOLVABLE_GROUP); - if (!groups) - return NULL; - - char* string = pakfire_string_join(groups, " "); - - // Free array - for (char** group = groups; *group; group++) - free(*group); - free(groups); - - return string; -} - -PAKFIRE_EXPORT void pakfire_package_set_groups(struct pakfire_package* pkg, const char* groups) { - char** list = pakfire_string_split(groups, ' '); - if (!list) - return; - - for (char** group = list; *group; group++) { - pakfire_package_add_string_array(pkg, SOLVABLE_GROUP, *group); - free(*group); - } - - free(list); -} - -PAKFIRE_EXPORT const char* pakfire_package_get_vendor(struct pakfire_package* pkg) { - return pakfire_package_get_string(pkg, SOLVABLE_VENDOR); -} - -PAKFIRE_EXPORT void pakfire_package_set_vendor(struct pakfire_package* pkg, const char* vendor) { - pakfire_package_set_string(pkg, SOLVABLE_VENDOR, vendor); -} - -PAKFIRE_EXPORT const char* pakfire_package_get_distribution(struct pakfire_package* pkg) { - return pakfire_package_get_string(pkg, SOLVABLE_DISTRIBUTION); -} - -PAKFIRE_EXPORT void pakfire_package_set_distribution(struct pakfire_package* pkg, const char* distribution) { - pakfire_package_set_string(pkg, SOLVABLE_DISTRIBUTION, distribution); -} - -PAKFIRE_EXPORT const char* pakfire_package_get_maintainer(struct pakfire_package* pkg) { - return pakfire_package_get_string(pkg, SOLVABLE_PACKAGER); -} - -PAKFIRE_EXPORT void pakfire_package_set_maintainer(struct pakfire_package* pkg, const char* maintainer) { - pakfire_package_set_string(pkg, SOLVABLE_PACKAGER, maintainer); -} - static int pakfire_package_make_cache_path(struct pakfire_package* pkg) { const char* filename = pakfire_package_get_filename(pkg); @@ -749,9 +585,9 @@ static const char* evr2vr(const char* evr) { static const char* pakfire_package_make_filename(struct pakfire_package* pkg) { if (!*pkg->filename) { - const char* name = pakfire_package_get_name(pkg); - const char* evr = pakfire_package_get_evr(pkg); - const char* arch = pakfire_package_get_arch(pkg); + const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME); + const char* evr = pakfire_package_get_string(pkg, PAKFIRE_PKG_EVR); + const char* arch = pakfire_package_get_string(pkg, PAKFIRE_PKG_ARCH); if (!name || !evr || !arch) return NULL; @@ -1161,16 +997,19 @@ PAKFIRE_EXPORT char* pakfire_package_dump(struct pakfire_package* pkg, int flags char* string = ""; // Name - const char* name = pakfire_package_get_name(pkg); - pakfire_package_dump_add_line(&string, _("Name"), name); + const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME); + if (name) + pakfire_package_dump_add_line(&string, _("Name"), name); // EVR - const char* evr = pakfire_package_get_evr(pkg); - pakfire_package_dump_add_line(&string, _("Version"), evr); + const char* evr = pakfire_package_get_string(pkg, PAKFIRE_PKG_EVR); + if (evr) + pakfire_package_dump_add_line(&string, _("Version"), evr); // Arch - const char* arch = pakfire_package_get_arch(pkg); - pakfire_package_dump_add_line(&string, _("Arch"), arch); + const char* arch = pakfire_package_get_string(pkg, PAKFIRE_PKG_ARCH); + if (arch) + pakfire_package_dump_add_line(&string, _("Arch"), arch); // Size size_t size = pakfire_package_get_size(pkg); @@ -1202,27 +1041,29 @@ PAKFIRE_EXPORT char* pakfire_package_dump(struct pakfire_package* pkg, int flags } // Summary - const char* summary = pakfire_package_get_summary(pkg); - pakfire_package_dump_add_line(&string, _("Summary"), summary); + const char* summary = pakfire_package_get_string(pkg, PAKFIRE_PKG_SUMMARY); + if (summary) + pakfire_package_dump_add_line(&string, _("Summary"), summary); // Description - const char* description = pakfire_package_get_description(pkg); + const char* description = pakfire_package_get_string(pkg, PAKFIRE_PKG_DESCRIPTION); if (description) pakfire_package_dump_add_lines(&string, _("Description"), description); // Groups - const char* groups = pakfire_package_get_groups(pkg); - if (groups) { + const char* groups = pakfire_package_get_string(pkg, PAKFIRE_PKG_GROUPS); + if (groups) pakfire_package_dump_add_lines(&string, _("Groups"), groups); - } // URL - const char* url = pakfire_package_get_url(pkg); - pakfire_package_dump_add_line(&string, _("URL"), url); + const char* url = pakfire_package_get_string(pkg, PAKFIRE_PKG_URL); + if (url) + pakfire_package_dump_add_line(&string, _("URL"), url); // License - const char* license = pakfire_package_get_license(pkg); - pakfire_package_dump_add_line(&string, _("License"), license); + const char* license = pakfire_package_get_string(pkg, PAKFIRE_PKG_LICENSE); + if (license) + pakfire_package_dump_add_line(&string, _("License"), license); if (flags & PAKFIRE_PKG_DUMP_LONG) { // Install Time @@ -1232,21 +1073,24 @@ PAKFIRE_EXPORT char* pakfire_package_dump(struct pakfire_package* pkg, int flags } // Distribution - const char* distro = pakfire_package_get_distribution(pkg); + const char* distro = pakfire_package_get_string(pkg, PAKFIRE_PKG_DISTRO); if (distro) pakfire_package_dump_add_line(&string, _("Distribution"), distro); // Maintainer - const char* maintainer = pakfire_package_get_maintainer(pkg); - pakfire_package_dump_add_line(&string, _("Maintainer"), maintainer); + const char* maintainer = pakfire_package_get_string(pkg, PAKFIRE_PKG_MAINTAINER); + if (maintainer) + pakfire_package_dump_add_line(&string, _("Maintainer"), maintainer); // Vendor - const char* vendor = pakfire_package_get_vendor(pkg); - pakfire_package_dump_add_line(&string, _("Vendor"), vendor); + const char* vendor = pakfire_package_get_string(pkg, PAKFIRE_PKG_VENDOR); + if (vendor) + pakfire_package_dump_add_line(&string, _("Vendor"), vendor); // UUID - const char* uuid = pakfire_package_get_uuid(pkg); - pakfire_package_dump_add_line(&string, _("UUID"), uuid); + const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID); + if (uuid) + pakfire_package_dump_add_line(&string, _("UUID"), uuid); // Build ID const char* build_id = pakfire_package_get_build_id(pkg); @@ -1436,7 +1280,7 @@ static int pakfire_package_append_file(struct pakfire_package* pkg, const char* struct pakfire_repo* repo = pakfire_package_get_repo(pkg); if (!repo) { ERROR(pkg->pakfire, "Could not find repository for %s: %m\n", - pakfire_package_get_nevra(pkg)); + pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA)); return 1; } @@ -1751,7 +1595,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) { int r = 0; // Name - const char* name = pakfire_package_get_name(pkg); + const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME); if (name) { r = pakfire_json_add_string(pkg->pakfire, md, "name", name); if (r) @@ -1759,7 +1603,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) { } // EVR - const char* evr = pakfire_package_get_evr(pkg); + const char* evr = pakfire_package_get_string(pkg, PAKFIRE_PKG_EVR); if (evr) { r = pakfire_json_add_string(pkg->pakfire, md, "evr", evr); if (r) @@ -1767,7 +1611,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) { } // Arch - const char* arch = pakfire_package_get_arch(pkg); + const char* arch = pakfire_package_get_string(pkg, PAKFIRE_PKG_ARCH); if (arch) { r = pakfire_json_add_string(pkg->pakfire, md, "arch", arch); if (r) @@ -1775,7 +1619,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) { } // Vendor - const char* vendor = pakfire_package_get_vendor(pkg); + const char* vendor = pakfire_package_get_string(pkg, PAKFIRE_PKG_VENDOR); if (vendor) { r = pakfire_json_add_string(pkg->pakfire, md, "vendor", vendor); if (r) @@ -1783,7 +1627,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) { } // Distribution - const char* distribution = pakfire_package_get_distribution(pkg); + const char* distribution = pakfire_package_get_string(pkg, PAKFIRE_PKG_DISTRO); if (distribution) { r = pakfire_json_add_string(pkg->pakfire, md, "distribution", distribution); if (r) @@ -1791,7 +1635,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) { } // UUID - const char* uuid = pakfire_package_get_uuid(pkg); + const char* uuid = pakfire_package_get_string(pkg, PAKFIRE_PKG_UUID); if (uuid) { r = pakfire_json_add_string(pkg->pakfire, md, "uuid", uuid); if (r) @@ -1799,24 +1643,15 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) { } // Groups - char* groups = pakfire_package_get_groups(pkg); + const char* groups = pakfire_package_get_string(pkg, PAKFIRE_PKG_GROUPS); if (groups) { r = pakfire_json_add_string(pkg->pakfire, md, "groups", groups); - free(groups); - if (r) - goto ERROR; - } - - // Distribution - const char* distro = pakfire_package_get_distribution(pkg); - if (distro) { - r = pakfire_json_add_string(pkg->pakfire, md, "distribution", distro); if (r) goto ERROR; } // Maintainer - const char* maintainer = pakfire_package_get_maintainer(pkg); + const char* maintainer = pakfire_package_get_string(pkg, PAKFIRE_PKG_MAINTAINER); if (maintainer) { r = pakfire_json_add_string(pkg->pakfire, md, "maintainer", maintainer); if (r) @@ -1824,7 +1659,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) { } // URL - const char* url = pakfire_package_get_url(pkg); + const char* url = pakfire_package_get_string(pkg, PAKFIRE_PKG_URL); if (url) { r = pakfire_json_add_string(pkg->pakfire, md, "url", url); if (r) @@ -1832,7 +1667,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) { } // License - const char* license = pakfire_package_get_license(pkg); + const char* license = pakfire_package_get_string(pkg, PAKFIRE_PKG_LICENSE); if (license) { r = pakfire_json_add_string(pkg->pakfire, md, "license", license); if (r) @@ -1840,7 +1675,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) { } // Summary - const char* summary = pakfire_package_get_summary(pkg); + const char* summary = pakfire_package_get_string(pkg, PAKFIRE_PKG_SUMMARY); if (summary) { r = pakfire_json_add_string(pkg->pakfire, md, "summary", summary); if (r) @@ -1848,7 +1683,7 @@ struct json_object* pakfire_package_to_json(struct pakfire_package* pkg) { } // Description - const char* description = pakfire_package_get_description(pkg); + const char* description = pakfire_package_get_string(pkg, PAKFIRE_PKG_DESCRIPTION); if (description) { r = pakfire_json_add_string(pkg->pakfire, md, "description", description); if (r) diff --git a/src/libpakfire/packager.c b/src/libpakfire/packager.c index ecc3b4eb6..8226c296c 100644 --- a/src/libpakfire/packager.c +++ b/src/libpakfire/packager.c @@ -113,7 +113,7 @@ int pakfire_packager_create(struct pakfire_packager** packager, goto ERROR; } - pakfire_package_set_distribution(pkg, tag); + pakfire_package_set_string(pkg, PAKFIRE_PKG_DISTRO, tag); // Set build host pakfire_package_set_build_host(pkg, pakfire_hostname()); @@ -179,7 +179,7 @@ const char* pakfire_packager_filename(struct pakfire_packager* packager) { if (pakfire_package_is_source(packager->pkg)) pakfire_string_set(packager->filename, filename); else { - const char* arch = pakfire_package_get_arch(packager->pkg); + const char* arch = pakfire_package_get_string(packager->pkg, PAKFIRE_PKG_ARCH); pakfire_string_format(packager->filename, "%s/%s", arch, filename); } @@ -348,7 +348,7 @@ int pakfire_packager_finish(struct pakfire_packager* packager, FILE* f) { struct archive* a = NULL; int r = 1; - const char* nevra = pakfire_package_get_nevra(packager->pkg); + const char* nevra = pakfire_package_get_string(packager->pkg, PAKFIRE_PKG_NEVRA); // Add requires feature markers if (pakfire_package_has_rich_deps(packager->pkg)) diff --git a/src/libpakfire/parser.c b/src/libpakfire/parser.c index e0baa96e4..ee9420e01 100644 --- a/src/libpakfire/parser.c +++ b/src/libpakfire/parser.c @@ -928,7 +928,7 @@ int pakfire_parser_create_package(struct pakfire_parser* parser, goto CLEANUP; } - pakfire_package_set_uuid(*pkg, uuid); + pakfire_package_set_string(*pkg, PAKFIRE_PKG_UUID, uuid); free(uuid); // Set build time @@ -939,15 +939,15 @@ int pakfire_parser_create_package(struct pakfire_parser* parser, // Assign more attributes const struct attribute { const char* name; - void(*func)(struct pakfire_package* pkg, const char* value); + const enum pakfire_package_key key; } attributes[] = { - { "summary", pakfire_package_set_summary, }, - { "description", pakfire_package_set_description, }, - { "license", pakfire_package_set_license, }, - { "url", pakfire_package_set_url, }, - { "groups", pakfire_package_set_groups, }, - { "vendor", pakfire_package_set_vendor, }, - { "maintainer", pakfire_package_set_maintainer, }, + { "summary", PAKFIRE_PKG_SUMMARY }, + { "description", PAKFIRE_PKG_DESCRIPTION, }, + { "license", PAKFIRE_PKG_LICENSE, }, + { "url", PAKFIRE_PKG_URL, }, + { "groups", PAKFIRE_PKG_GROUPS, }, + { "vendor", PAKFIRE_PKG_VENDOR, }, + { "maintainer", PAKFIRE_PKG_MAINTAINER, }, { NULL }, }; @@ -956,8 +956,13 @@ int pakfire_parser_create_package(struct pakfire_parser* parser, if (!value) continue; - a->func(*pkg, value); + r = pakfire_package_set_string(*pkg, a->key, value); free(value); + + if (r) { + ERROR(parser->pakfire, "Could not set %s: %m\n", a->name); + goto CLEANUP; + } } // Fetch build dependencies diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index 38ab62401..b0558c9a2 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -1025,7 +1025,7 @@ static int pakfire_repo_delete_all_packages( if (!pkg) return 1; - const char* nevra = pakfire_package_get_nevra(pkg); + const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA); const char* path = pakfire_package_get_path(pkg); // If prefix is set, skip anything that doesn't match diff --git a/src/libpakfire/transaction.c b/src/libpakfire/transaction.c index 53e509d11..11675307d 100644 --- a/src/libpakfire/transaction.c +++ b/src/libpakfire/transaction.c @@ -387,9 +387,9 @@ static void pakfire_transaction_add_package(char*** lines, size_t width, struct return; pakfire_transaction_add_line(lines, width, - pakfire_package_get_name(pkg), - pakfire_package_get_arch(pkg), - pakfire_package_get_evr(pkg), + pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME), + pakfire_package_get_string(pkg, PAKFIRE_PKG_ARCH), + pakfire_package_get_string(pkg, PAKFIRE_PKG_EVR), pakfire_repo_get_name(repo), size ); @@ -403,7 +403,7 @@ static void pakfire_transaction_add_package_change(char*** lines, size_t width, pakfire_transaction_add_package(lines, width, new_pkg); pakfire_transaction_append_line(lines, - " --> %s\n", pakfire_package_get_nevra(old_pkg)); + " --> %s\n", pakfire_package_get_string(old_pkg, PAKFIRE_PKG_NEVRA)); } static void pakfire_transaction_add_separator(char*** lines, size_t width) { @@ -679,7 +679,7 @@ static int pakfire_transaction_check(struct pakfire_transaction* transaction) { static int pakfire_transaction_verify(struct pakfire_transaction* transaction, struct pakfire_package* pkg, struct pakfire_archive* archive) { - const char* nevra = pakfire_package_get_nevra(pkg); + const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA); // Nothing to do if this step does not have an archive if (!archive) { @@ -725,7 +725,7 @@ static int pakfire_transaction_run_script(struct pakfire_transaction* transactio static int pakfire_transaction_extract(struct pakfire_transaction* transaction, struct pakfire_package* pkg, struct pakfire_archive* archive) { - const char* nevra = pakfire_package_get_nevra(pkg); + const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA); // Update status pakfire_transaction_status(transaction, _("Installing %s..."), nevra); @@ -815,7 +815,7 @@ static int pakfire_transaction_package_is_userinstalled( if (!transaction->userinstalled) return 0; - const char* name = pakfire_package_get_name(pkg); + const char* name = pakfire_package_get_string(pkg, PAKFIRE_PKG_NAME); // Check if the package is on the list for (char** elem = transaction->userinstalled; *elem; elem++) { @@ -835,7 +835,7 @@ static int pakfire_transaction_run_step(struct pakfire_transaction* transaction, } DEBUG(transaction->pakfire, "Running %s for %s\n", - pakfire_action_type_string(action), pakfire_package_get_nevra(pkg)); + pakfire_action_type_string(action), pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA)); enum pakfire_steps type = pakfire_transaction_get_step_type(transaction, pkg); @@ -1050,7 +1050,7 @@ static int pakfire_transaction_open_archives(struct pakfire_transaction* transac transaction->archives[i] = pakfire_package_get_archive(pkg); if (!transaction->archives[i]) { ERROR(transaction->pakfire, "Could not open archive for %s: %m\n", - pakfire_package_get_nevra(pkg)); + pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA)); return 1; } } @@ -1132,7 +1132,7 @@ static int pakfire_transaction_download_package(struct pakfire_transaction* tran // Fetch mirrorlist mirrorlist = pakfire_repo_get_mirrorlist(repo); - const char* nevra = pakfire_package_get_nevra(pkg); + const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA); if (!nevra) goto ERROR; @@ -1220,7 +1220,7 @@ PAKFIRE_EXPORT int pakfire_transaction_download(struct pakfire_transaction* tran // Enqueue download r = pakfire_transaction_download_package(transaction, downloader, pkg); if (r) { - const char* nevra = pakfire_package_get_nevra(pkg); + const char* nevra = pakfire_package_get_string(pkg, PAKFIRE_PKG_NEVRA); ERROR(transaction->pakfire, "Could not add download to queue: %s: %m\n", nevra); goto ERROR; diff --git a/tests/libpakfire/packager.c b/tests/libpakfire/packager.c index e2592585c..a1a18b8be 100644 --- a/tests/libpakfire/packager.c +++ b/tests/libpakfire/packager.c @@ -85,8 +85,8 @@ static int test_compare_metadata(const struct test* t) { ASSERT(pkg1); // Set all metadata - pakfire_package_set_summary(pkg1, "SUMMARY"); - pakfire_package_set_description(pkg1, "DESCRIPTION"); + pakfire_package_set_string(pkg1, PAKFIRE_PKG_SUMMARY, "SUMMARY"); + pakfire_package_set_string(pkg1, PAKFIRE_PKG_DESCRIPTION, "DESCRIPTION"); // Create packager ASSERT_SUCCESS(pakfire_packager_create(&packager, t->pakfire, pkg1)); @@ -114,23 +114,23 @@ static int test_compare_metadata(const struct test* t) { } // Compare name - s = pakfire_package_get_name(pkg2); + s = pakfire_package_get_string(pkg2, PAKFIRE_PKG_NAME); ASSERT_STRING_EQUALS(s, "test"); // Compare evr - s = pakfire_package_get_evr(pkg2); + s = pakfire_package_get_string(pkg2, PAKFIRE_PKG_EVR); ASSERT_STRING_EQUALS(s, "1.0-1"); // Compare arch - s = pakfire_package_get_arch(pkg2); + s = pakfire_package_get_string(pkg2, PAKFIRE_PKG_ARCH); ASSERT_STRING_EQUALS(s, "x86_64"); // Compare summary - s = pakfire_package_get_summary(pkg2); + s = pakfire_package_get_string(pkg2, PAKFIRE_PKG_SUMMARY); ASSERT_STRING_EQUALS(s, "SUMMARY"); // Compare description - s = pakfire_package_get_description(pkg2); + s = pakfire_package_get_string(pkg2, PAKFIRE_PKG_DESCRIPTION); ASSERT_STRING_EQUALS(s, "DESCRIPTION"); // Everything passed