mirror of
https://github.com/moparisthebest/pacman
synced 2024-10-31 15:45:03 -04:00
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>
This commit is contained in:
parent
b94e8ecd1f
commit
13235ba65a
@ -470,9 +470,6 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
|
|||||||
|
|
||||||
/* we'll need to save some record for backup checks later */
|
/* we'll need to save some record for backup checks later */
|
||||||
oldpkg = _alpm_pkg_dup(local);
|
oldpkg = _alpm_pkg_dup(local);
|
||||||
/* make sure all infos are loaded because the database entry
|
|
||||||
* will be removed soon */
|
|
||||||
_alpm_local_db_read(oldpkg->origin_data.db, oldpkg, INFRQ_ALL);
|
|
||||||
|
|
||||||
EVENT(trans, PM_TRANS_EVT_UPGRADE_START, newpkg, oldpkg);
|
EVENT(trans, PM_TRANS_EVT_UPGRADE_START, newpkg, oldpkg);
|
||||||
_alpm_log(handle, PM_LOG_DEBUG, "upgrading package %s-%s\n",
|
_alpm_log(handle, PM_LOG_DEBUG, "upgrading package %s-%s\n",
|
||||||
|
@ -41,10 +41,12 @@
|
|||||||
#include "package.h"
|
#include "package.h"
|
||||||
#include "deps.h"
|
#include "deps.h"
|
||||||
|
|
||||||
|
static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq);
|
||||||
|
|
||||||
#define LAZY_LOAD(info, errret) \
|
#define LAZY_LOAD(info, errret) \
|
||||||
do { \
|
do { \
|
||||||
if(pkg->origin != PKG_FROM_FILE && !(pkg->infolevel & info)) { \
|
if(!(pkg->infolevel & info)) { \
|
||||||
_alpm_local_db_read(pkg->origin_data.db, pkg, info); \
|
local_db_read(pkg, info); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} 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)
|
static int _cache_has_scriptlet(alpm_pkg_t *pkg)
|
||||||
{
|
{
|
||||||
if(!(pkg->infolevel & INFRQ_SCRIPTLET)) {
|
LAZY_LOAD(INFRQ_SCRIPTLET, NULL);
|
||||||
_alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_SCRIPTLET);
|
|
||||||
}
|
|
||||||
return pkg->scriptlet;
|
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)
|
static alpm_list_t *_cache_get_files(alpm_pkg_t *pkg)
|
||||||
{
|
{
|
||||||
if(pkg->origin == PKG_FROM_LOCALDB
|
LAZY_LOAD(INFRQ_FILES, NULL);
|
||||||
&& !(pkg->infolevel & INFRQ_FILES)) {
|
|
||||||
_alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
|
||||||
}
|
|
||||||
return pkg->files;
|
return pkg->files;
|
||||||
}
|
}
|
||||||
|
|
||||||
static alpm_list_t *_cache_get_backup(alpm_pkg_t *pkg)
|
static alpm_list_t *_cache_get_backup(alpm_pkg_t *pkg)
|
||||||
{
|
{
|
||||||
if(pkg->origin == PKG_FROM_LOCALDB
|
LAZY_LOAD(INFRQ_FILES, NULL);
|
||||||
&& !(pkg->infolevel & INFRQ_FILES)) {
|
|
||||||
_alpm_local_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
|
||||||
}
|
|
||||||
return pkg->backup;
|
return pkg->backup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,6 +233,11 @@ static int _cache_changelog_close(const alpm_pkg_t UNUSED *pkg, void *fp)
|
|||||||
return fclose((FILE *)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
|
/** The local database operations struct. Get package fields through
|
||||||
* lazy accessor methods that handle any backend loading and caching
|
* 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_open = _cache_changelog_open,
|
||||||
.changelog_read = _cache_changelog_read,
|
.changelog_read = _cache_changelog_read,
|
||||||
.changelog_close = _cache_changelog_close,
|
.changelog_close = _cache_changelog_close,
|
||||||
|
|
||||||
|
.force_load = _cache_force_load,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int checkdbdir(alpm_db_t *db)
|
static int checkdbdir(alpm_db_t *db)
|
||||||
@ -460,7 +461,7 @@ static int local_db_populate(alpm_db_t *db)
|
|||||||
pkg->handle = db->handle;
|
pkg->handle = db->handle;
|
||||||
|
|
||||||
/* explicitly read with only 'BASE' data, accessors will handle the rest */
|
/* 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_log(db->handle, PM_LOG_ERROR, _("corrupted database entry '%s'\n"), name);
|
||||||
_alpm_pkg_free(pkg);
|
_alpm_pkg_free(pkg);
|
||||||
continue;
|
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;
|
FILE *fp = NULL;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char line[1024];
|
char line[1024];
|
||||||
char *pkgpath = NULL;
|
char *pkgpath = NULL;
|
||||||
|
alpm_db_t *db = info->origin_data.db;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* bitmask logic here:
|
/* bitmask logic here:
|
||||||
* infolevel: 00001111
|
* infolevel: 00001111
|
||||||
|
@ -87,7 +87,6 @@ alpm_db_t *_alpm_db_register_sync(alpm_handle_t *handle, const char *treename,
|
|||||||
void _alpm_db_unregister(alpm_db_t *db);
|
void _alpm_db_unregister(alpm_db_t *db);
|
||||||
|
|
||||||
/* be_*.c, backend specific calls */
|
/* be_*.c, backend specific calls */
|
||||||
int _alpm_local_db_read(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq);
|
|
||||||
int _alpm_local_db_prepare(alpm_db_t *db, alpm_pkg_t *info);
|
int _alpm_local_db_prepare(alpm_db_t *db, alpm_pkg_t *info);
|
||||||
int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq);
|
int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq);
|
||||||
int _alpm_local_db_remove(alpm_db_t *db, alpm_pkg_t *info);
|
int _alpm_local_db_remove(alpm_db_t *db, alpm_pkg_t *info);
|
||||||
|
@ -126,6 +126,8 @@ static int _pkg_changelog_close(const alpm_pkg_t UNUSED *pkg,
|
|||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _pkg_force_load(alpm_pkg_t UNUSED *pkg) { return 0; }
|
||||||
|
|
||||||
/** The standard package operations struct. Get fields directly from the
|
/** The standard package operations struct. Get fields directly from the
|
||||||
* struct itself with no abstraction layer or any type of lazy loading.
|
* struct itself with no abstraction layer or any type of lazy loading.
|
||||||
*/
|
*/
|
||||||
@ -157,6 +159,8 @@ struct pkg_operations default_pkg_ops = {
|
|||||||
.changelog_open = _pkg_changelog_open,
|
.changelog_open = _pkg_changelog_open,
|
||||||
.changelog_read = _pkg_changelog_read,
|
.changelog_read = _pkg_changelog_read,
|
||||||
.changelog_close = _pkg_changelog_close,
|
.changelog_close = _pkg_changelog_close,
|
||||||
|
|
||||||
|
.force_load = _pkg_force_load,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Public functions for getting package information. These functions
|
/* Public functions for getting package information. These functions
|
||||||
@ -437,6 +441,10 @@ alpm_pkg_t *_alpm_pkg_dup(alpm_pkg_t *pkg)
|
|||||||
alpm_pkg_t *newpkg;
|
alpm_pkg_t *newpkg;
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
|
|
||||||
|
if(pkg->ops->force_load(pkg)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
CALLOC(newpkg, 1, sizeof(alpm_pkg_t), goto cleanup);
|
CALLOC(newpkg, 1, sizeof(alpm_pkg_t), goto cleanup);
|
||||||
|
|
||||||
newpkg->name_hash = pkg->name_hash;
|
newpkg->name_hash = pkg->name_hash;
|
||||||
|
@ -76,6 +76,8 @@ struct pkg_operations {
|
|||||||
size_t (*changelog_read) (void *, size_t, const alpm_pkg_t *, const void *);
|
size_t (*changelog_read) (void *, size_t, const alpm_pkg_t *, const void *);
|
||||||
int (*changelog_close) (const alpm_pkg_t *, void *);
|
int (*changelog_close) (const alpm_pkg_t *, void *);
|
||||||
|
|
||||||
|
int (*force_load) (alpm_pkg_t *);
|
||||||
|
|
||||||
/* still to add:
|
/* still to add:
|
||||||
* checkmd5sum() ?
|
* checkmd5sum() ?
|
||||||
* compute_requiredby()
|
* compute_requiredby()
|
||||||
|
Loading…
Reference in New Issue
Block a user