summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/package.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-07-07 09:39:39 -0500
committerAllan McRae <allan@archlinux.org>2010-10-13 23:53:17 +1000
commit49176461a6b476e673e232075c95f07963750f74 (patch)
tree0910d7e4f650623e3e2c81883f18153384a09f03 /lib/libalpm/package.c
parent5fcb005ebd270c1ecff3403695680145253961a2 (diff)
downloadpacman-49176461a6b476e673e232075c95f07963750f74.tar.xz
Unify caching concerns in package accessors
Move almost all of the caching related stuff into a single #define (which should maybe even just be a static function) so we don't duplicate logic all over the place. This also makes the code a heck of a lot shorter and means further changes to this stuff don't have to touch each and every getter function. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/package.c')
-rw-r--r--lib/libalpm/package.c211
1 files changed, 30 insertions, 181 deletions
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 717d32ce..8c572810 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -100,18 +100,19 @@ int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg)
return(retval);
}
+#define LAZY_LOAD(info, errret) \
+ do { \
+ ALPM_LOG_FUNC; \
+ ASSERT(handle != NULL, return(errret)); \
+ ASSERT(pkg != NULL, return(errret)); \
+ if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & info)) { \
+ _alpm_db_read(pkg->origin_data.db, pkg, info); \
+ } \
+ } while(0)
+
const char SYMEXPORT *alpm_pkg_get_filename(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
-
+ LAZY_LOAD(INFRQ_DESC, NULL);
return pkg->filename;
}
@@ -129,267 +130,115 @@ const char SYMEXPORT *alpm_pkg_get_version(pmpkg_t *pkg)
const char SYMEXPORT *alpm_pkg_get_desc(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, NULL);
return pkg->desc;
}
const char SYMEXPORT *alpm_pkg_get_url(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, NULL);
return pkg->url;
}
time_t SYMEXPORT alpm_pkg_get_builddate(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(0));
- ASSERT(pkg != NULL, return(0));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, 0);
return pkg->builddate;
}
time_t SYMEXPORT alpm_pkg_get_installdate(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(0));
- ASSERT(pkg != NULL, return(0));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, 0);
return pkg->installdate;
}
const char SYMEXPORT *alpm_pkg_get_packager(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, NULL);
return pkg->packager;
}
const char SYMEXPORT *alpm_pkg_get_md5sum(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, NULL);
return pkg->md5sum;
}
const char SYMEXPORT *alpm_pkg_get_arch(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, NULL);
return pkg->arch;
}
off_t SYMEXPORT alpm_pkg_get_size(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(-1));
- ASSERT(pkg != NULL, return(-1));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, -1);
return pkg->size;
}
off_t SYMEXPORT alpm_pkg_get_isize(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(-1));
- ASSERT(pkg != NULL, return(-1));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, -1);
return pkg->isize;
}
pmpkgreason_t SYMEXPORT alpm_pkg_get_reason(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(-1));
- ASSERT(pkg != NULL, return(-1));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, -1);
return pkg->reason;
}
alpm_list_t SYMEXPORT *alpm_pkg_get_licenses(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, NULL);
return pkg->licenses;
}
alpm_list_t SYMEXPORT *alpm_pkg_get_groups(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, NULL);
return pkg->groups;
}
int SYMEXPORT alpm_pkg_has_force(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(-1));
- ASSERT(pkg != NULL, return(-1));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, -1);
return pkg->force;
}
alpm_list_t SYMEXPORT *alpm_pkg_get_depends(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
- }
+ LAZY_LOAD(INFRQ_DEPENDS, NULL);
return pkg->depends;
}
alpm_list_t SYMEXPORT *alpm_pkg_get_optdepends(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
- }
+ LAZY_LOAD(INFRQ_DEPENDS, NULL);
return pkg->optdepends;
}
alpm_list_t SYMEXPORT *alpm_pkg_get_conflicts(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
- }
+ LAZY_LOAD(INFRQ_DEPENDS, NULL);
return pkg->conflicts;
}
alpm_list_t SYMEXPORT *alpm_pkg_get_provides(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
- }
+ LAZY_LOAD(INFRQ_DEPENDS, NULL);
return pkg->provides;
}
alpm_list_t SYMEXPORT *alpm_pkg_get_deltas(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DELTAS)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DELTAS);
- }
+ LAZY_LOAD(INFRQ_DELTAS, NULL);
return pkg->deltas;
}
alpm_list_t SYMEXPORT *alpm_pkg_get_replaces(pmpkg_t *pkg)
{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(pkg != NULL, return(NULL));
-
- if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
- }
+ LAZY_LOAD(INFRQ_DESC, NULL);
return pkg->replaces;
}