diff options
author | Dan McGee <dan@archlinux.org> | 2011-06-29 05:02:58 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-06-30 18:51:49 +0200 |
commit | 13235ba65ab55d852dbdc0acabdc047442e74e28 (patch) | |
tree | 85adbf195f380908af76f9527e92bea451dcf0a9 /lib/libalpm/be_local.c | |
parent | b94e8ecd1fec4426baab8c90e7fc0d5583acdbef (diff) | |
download | pacman-13235ba65ab55d852dbdc0acabdc047442e74e28.tar.gz pacman-13235ba65ab55d852dbdc0acabdc047442e74e28.tar.xz |
Make local_db_read() private to the local backend
There is little need to expose the guts of this function even within the
library. Make it static in be_local.c, and clean up a few other things
since we know exactly where it is being called from:
* Remove unnecessary origin checks in _cache_get_*() methods- if you are
calling a cache method your package type will be correct.
* Remove sanity checks within local_db_read() itself- packages will
always have a name and version if they get this far, and the package
object will never be NULL either.
The one case calling this from outside the backend was in add.c, where
we forced a full load of a package before we duplicated it. Move this
concern elsewhere and have pkg_dup() always force a full package load
via a new force_load() function on the operations callback struct.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/be_local.c')
-rw-r--r-- | lib/libalpm/be_local.c | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 2ee71cc0..c10c9e3c 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -41,10 +41,12 @@ #include "package.h" #include "deps.h" +static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq); + #define LAZY_LOAD(info, errret) \ do { \ - if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & info)) { \ - _alpm_local_db_read(pkg->origin_data.db, pkg, info); \ + if(!(pkg->infolevel & info)) { \ + local_db_read(pkg, info); \ } \ } while(0) @@ -135,9 +137,7 @@ static alpm_list_t *_cache_get_groups(alpm_pkg_t *pkg) static int _cache_has_scriptlet(alpm_pkg_t *pkg) { - if(!(pkg->infolevel & INFRQ_SCRIPTLET)) { - _alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_SCRIPTLET); - } + LAZY_LOAD(INFRQ_SCRIPTLET, NULL); return pkg->scriptlet; } @@ -179,19 +179,13 @@ static alpm_list_t *_cache_get_deltas(alpm_pkg_t UNUSED *pkg) static alpm_list_t *_cache_get_files(alpm_pkg_t *pkg) { - if(pkg->origin == PKG_FROM_LOCALDB - && !(pkg->infolevel & INFRQ_FILES)) { - _alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_FILES); - } + LAZY_LOAD(INFRQ_FILES, NULL); return pkg->files; } static alpm_list_t *_cache_get_backup(alpm_pkg_t *pkg) { - if(pkg->origin == PKG_FROM_LOCALDB - && !(pkg->infolevel & INFRQ_FILES)) { - _alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_FILES); - } + LAZY_LOAD(INFRQ_FILES, NULL); return pkg->backup; } @@ -239,6 +233,11 @@ static int _cache_changelog_close(const alpm_pkg_t UNUSED *pkg, void *fp) return fclose((FILE *)fp); } +static int _cache_force_load(alpm_pkg_t *pkg) +{ + return local_db_read(pkg, INFRQ_ALL); +} + /** The local database operations struct. Get package fields through * lazy accessor methods that handle any backend loading and caching @@ -271,6 +270,8 @@ static struct pkg_operations local_pkg_ops = { .changelog_open = _cache_changelog_open, .changelog_read = _cache_changelog_read, .changelog_close = _cache_changelog_close, + + .force_load = _cache_force_load, }; static int checkdbdir(alpm_db_t *db) @@ -460,7 +461,7 @@ static int local_db_populate(alpm_db_t *db) pkg->handle = db->handle; /* explicitly read with only 'BASE' data, accessors will handle the rest */ - if(_alpm_local_db_read(db, pkg, INFRQ_BASE) == -1) { + if(local_db_read(pkg, INFRQ_BASE) == -1) { _alpm_log(db->handle, PM_LOG_ERROR, _("corrupted database entry '%s'\n"), name); _alpm_pkg_free(pkg); continue; @@ -498,25 +499,13 @@ static char *get_pkgpath(alpm_db_t *db, alpm_pkg_t *info) } -int _alpm_local_db_read(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq) +static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq) { FILE *fp = NULL; char path[PATH_MAX]; char line[1024]; char *pkgpath = NULL; - - if(info == NULL || info->name == NULL || info->version == NULL) { - _alpm_log(db->handle, PM_LOG_DEBUG, - "invalid package entry provided to _alpm_local_db_read, skipping\n"); - return -1; - } - - if(info->origin != PKG_FROM_LOCALDB) { - _alpm_log(db->handle, PM_LOG_DEBUG, - "request to read info for a non-local package '%s', skipping...\n", - info->name); - return -1; - } + alpm_db_t *db = info->origin_data.db; /* bitmask logic here: * infolevel: 00001111 |