aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormorganamilo <morganamilo@archlinux.org>2021-12-04 10:26:57 +0000
committerAllan McRae <allan@archlinux.org>2022-03-08 09:56:53 +1000
commitbddfcc3f40ce1a19d4c9552cddbf2cab07c94d4b (patch)
treefd3df662a842d5e33764a85991168ed92fd47ec6
parent221905b5ae998dd578d346ebca8c2e35b1bb349c (diff)
libalpm: add getter for handle on db and pkg
db and pkg store a pointer to the handle for internal use but don't actually provide a way for a user to get it. Making this accessible is more convenient for front ends and FFI wrappers. For example, in other languages it's common to return the error value directly. To achieve this the python and rust wrappers also store their own pointer to the handle inside their own pkg/db wrappers. Exposing this would allow the wrappers to forgo the extra pointer and just return `pkg.get_handle().last_error()`.
-rw-r--r--lib/libalpm/alpm.h12
-rw-r--r--lib/libalpm/db.c6
-rw-r--r--lib/libalpm/package.c6
3 files changed, 24 insertions, 0 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 6b66fa09..cdf71fdc 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1281,6 +1281,12 @@ int alpm_unregister_all_syncdbs(alpm_handle_t *handle);
*/
int alpm_db_unregister(alpm_db_t *db);
+/** Get the handle of a package database.
+ * @param db pointer to the package database
+ * @return the alpm handle that the package database belongs to
+ */
+alpm_handle_t *alpm_db_get_handle(alpm_db_t *db);
+
/** Get the name of a package database.
* @param db pointer to the package database
* @return the name of the package database, NULL on error
@@ -2386,6 +2392,12 @@ int alpm_pkg_should_ignore(alpm_handle_t *handle, alpm_pkg_t *pkg);
* @{
*/
+/** Gets the handle of a package
+ * @param pkg a pointer to package
+ * @return the alpm handle that the package belongs to
+ */
+alpm_handle_t *alpm_pkg_get_handle(alpm_pkg_t *pkg);
+
/** Gets the name of the file from which the package was loaded.
* @param pkg a pointer to package
* @return a reference to an internal string
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 4a234f9c..ece8eae6 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -212,6 +212,12 @@ int SYMEXPORT alpm_db_remove_server(alpm_db_t *db, const char *url)
return ret;
}
+alpm_handle_t SYMEXPORT *alpm_db_get_handle(alpm_db_t *db)
+{
+ ASSERT(db != NULL, return NULL);
+ return db->handle;
+}
+
const char SYMEXPORT *alpm_db_get_name(const alpm_db_t *db)
{
ASSERT(db != NULL, return NULL);
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index e79d7d65..4d89dcd8 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -191,6 +191,12 @@ const char SYMEXPORT *alpm_pkg_get_base(alpm_pkg_t *pkg)
return pkg->ops->get_base(pkg);
}
+alpm_handle_t SYMEXPORT *alpm_pkg_get_handle(alpm_pkg_t *pkg)
+{
+ ASSERT(pkg != NULL, return NULL);
+ return pkg->handle;
+}
+
const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);