More package operations cleanup

Neither deltas nor filename attributes are ever present in the local
database, so we can remove all of the indirection for accessing these
attributes.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-09-02 22:07:06 -05:00
parent 7c956d5d4b
commit 7ea1ea88bb
6 changed files with 12 additions and 45 deletions

View file

@ -57,12 +57,6 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq);
* initialized. * initialized.
*/ */
static const char *_cache_get_filename(alpm_pkg_t *pkg)
{
LAZY_LOAD(INFRQ_DESC, NULL);
return pkg->filename;
}
static const char *_cache_get_desc(alpm_pkg_t *pkg) static const char *_cache_get_desc(alpm_pkg_t *pkg)
{ {
LAZY_LOAD(INFRQ_DESC, NULL); LAZY_LOAD(INFRQ_DESC, NULL);
@ -159,12 +153,6 @@ static alpm_list_t *_cache_get_replaces(alpm_pkg_t *pkg)
return pkg->replaces; return pkg->replaces;
} }
/* local packages can not have deltas */
static alpm_list_t *_cache_get_deltas(alpm_pkg_t UNUSED *pkg)
{
return NULL;
}
static alpm_filelist_t *_cache_get_files(alpm_pkg_t *pkg) static alpm_filelist_t *_cache_get_files(alpm_pkg_t *pkg)
{ {
LAZY_LOAD(INFRQ_FILES, NULL); LAZY_LOAD(INFRQ_FILES, NULL);
@ -230,7 +218,6 @@ static int _cache_force_load(alpm_pkg_t *pkg)
* logic. * logic.
*/ */
static struct pkg_operations local_pkg_ops = { static struct pkg_operations local_pkg_ops = {
.get_filename = _cache_get_filename,
.get_desc = _cache_get_desc, .get_desc = _cache_get_desc,
.get_url = _cache_get_url, .get_url = _cache_get_url,
.get_builddate = _cache_get_builddate, .get_builddate = _cache_get_builddate,
@ -247,7 +234,6 @@ static struct pkg_operations local_pkg_ops = {
.get_conflicts = _cache_get_conflicts, .get_conflicts = _cache_get_conflicts,
.get_provides = _cache_get_provides, .get_provides = _cache_get_provides,
.get_replaces = _cache_get_replaces, .get_replaces = _cache_get_replaces,
.get_deltas = _cache_get_deltas,
.get_files = _cache_get_files, .get_files = _cache_get_files,
.get_backup = _cache_get_backup, .get_backup = _cache_get_backup,

View file

@ -250,10 +250,7 @@ static alpm_list_t *find_unused(alpm_list_t *deltas, const char *to, off_t quota
alpm_list_t SYMEXPORT *alpm_pkg_unused_deltas(alpm_pkg_t *pkg) alpm_list_t SYMEXPORT *alpm_pkg_unused_deltas(alpm_pkg_t *pkg)
{ {
ASSERT(pkg != NULL, return NULL); ASSERT(pkg != NULL, return NULL);
return find_unused( return find_unused(pkg->deltas, pkg->filename, pkg->size * MAX_DELTA_RATIO);
alpm_pkg_get_deltas(pkg),
alpm_pkg_get_filename(pkg),
pkg->size * MAX_DELTA_RATIO);
} }
/** @} */ /** @} */

View file

@ -67,7 +67,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg)
ASSERT(pkg->origin == PKG_FROM_SYNCDB, ASSERT(pkg->origin == PKG_FROM_SYNCDB,
RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1)); RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1));
fpath = _alpm_filecache_find(pkg->handle, alpm_pkg_get_filename(pkg)); fpath = _alpm_filecache_find(pkg->handle, pkg->filename);
retval = _alpm_test_checksum(fpath, pkg->md5sum, ALPM_CSUM_MD5); retval = _alpm_test_checksum(fpath, pkg->md5sum, ALPM_CSUM_MD5);
@ -85,7 +85,6 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg)
* backend logic that needs lazy access, such as the local database through * backend logic that needs lazy access, such as the local database through
* a lazy-load cache. However, the defaults will work just fine for fully- * a lazy-load cache. However, the defaults will work just fine for fully-
* populated package structures. */ * populated package structures. */
static const char *_pkg_get_filename(alpm_pkg_t *pkg) { return pkg->filename; }
static const char *_pkg_get_desc(alpm_pkg_t *pkg) { return pkg->desc; } static const char *_pkg_get_desc(alpm_pkg_t *pkg) { return pkg->desc; }
static const char *_pkg_get_url(alpm_pkg_t *pkg) { return pkg->url; } static const char *_pkg_get_url(alpm_pkg_t *pkg) { return pkg->url; }
static time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; } static time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; }
@ -103,7 +102,6 @@ static alpm_list_t *_pkg_get_optdepends(alpm_pkg_t *pkg) { return pkg->optdepend
static alpm_list_t *_pkg_get_conflicts(alpm_pkg_t *pkg) { return pkg->conflicts; } static alpm_list_t *_pkg_get_conflicts(alpm_pkg_t *pkg) { return pkg->conflicts; }
static alpm_list_t *_pkg_get_provides(alpm_pkg_t *pkg) { return pkg->provides; } static alpm_list_t *_pkg_get_provides(alpm_pkg_t *pkg) { return pkg->provides; }
static alpm_list_t *_pkg_get_replaces(alpm_pkg_t *pkg) { return pkg->replaces; } static alpm_list_t *_pkg_get_replaces(alpm_pkg_t *pkg) { return pkg->replaces; }
static alpm_list_t *_pkg_get_deltas(alpm_pkg_t *pkg) { return pkg->deltas; }
static alpm_filelist_t *_pkg_get_files(alpm_pkg_t *pkg) { return &(pkg->files); } static alpm_filelist_t *_pkg_get_files(alpm_pkg_t *pkg) { return &(pkg->files); }
static alpm_list_t *_pkg_get_backup(alpm_pkg_t *pkg) { return pkg->backup; } static alpm_list_t *_pkg_get_backup(alpm_pkg_t *pkg) { return pkg->backup; }
@ -130,7 +128,6 @@ static int _pkg_force_load(alpm_pkg_t UNUSED *pkg) { return 0; }
* struct itself with no abstraction layer or any type of lazy loading. * struct itself with no abstraction layer or any type of lazy loading.
*/ */
struct pkg_operations default_pkg_ops = { struct pkg_operations default_pkg_ops = {
.get_filename = _pkg_get_filename,
.get_desc = _pkg_get_desc, .get_desc = _pkg_get_desc,
.get_url = _pkg_get_url, .get_url = _pkg_get_url,
.get_builddate = _pkg_get_builddate, .get_builddate = _pkg_get_builddate,
@ -148,7 +145,6 @@ struct pkg_operations default_pkg_ops = {
.get_conflicts = _pkg_get_conflicts, .get_conflicts = _pkg_get_conflicts,
.get_provides = _pkg_get_provides, .get_provides = _pkg_get_provides,
.get_replaces = _pkg_get_replaces, .get_replaces = _pkg_get_replaces,
.get_deltas = _pkg_get_deltas,
.get_files = _pkg_get_files, .get_files = _pkg_get_files,
.get_backup = _pkg_get_backup, .get_backup = _pkg_get_backup,
@ -166,7 +162,7 @@ const char SYMEXPORT *alpm_pkg_get_filename(alpm_pkg_t *pkg)
{ {
ASSERT(pkg != NULL, return NULL); ASSERT(pkg != NULL, return NULL);
pkg->handle->pm_errno = 0; pkg->handle->pm_errno = 0;
return pkg->ops->get_filename(pkg); return pkg->filename;
} }
const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg) const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg)
@ -256,6 +252,7 @@ const char SYMEXPORT *alpm_pkg_get_arch(alpm_pkg_t *pkg)
off_t SYMEXPORT alpm_pkg_get_size(alpm_pkg_t *pkg) off_t SYMEXPORT alpm_pkg_get_size(alpm_pkg_t *pkg)
{ {
ASSERT(pkg != NULL, return -1); ASSERT(pkg != NULL, return -1);
pkg->handle->pm_errno = 0;
return pkg->size; return pkg->size;
} }
@ -326,7 +323,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_deltas(alpm_pkg_t *pkg)
{ {
ASSERT(pkg != NULL, return NULL); ASSERT(pkg != NULL, return NULL);
pkg->handle->pm_errno = 0; pkg->handle->pm_errno = 0;
return pkg->ops->get_deltas(pkg); return pkg->deltas;
} }
alpm_filelist_t SYMEXPORT *alpm_pkg_get_files(alpm_pkg_t *pkg) alpm_filelist_t SYMEXPORT *alpm_pkg_get_files(alpm_pkg_t *pkg)

View file

@ -42,7 +42,6 @@
* defined default_pkg_ops struct to work just fine for their needs. * defined default_pkg_ops struct to work just fine for their needs.
*/ */
struct pkg_operations { struct pkg_operations {
const char *(*get_filename) (alpm_pkg_t *);
const char *(*get_desc) (alpm_pkg_t *); const char *(*get_desc) (alpm_pkg_t *);
const char *(*get_url) (alpm_pkg_t *); const char *(*get_url) (alpm_pkg_t *);
time_t (*get_builddate) (alpm_pkg_t *); time_t (*get_builddate) (alpm_pkg_t *);
@ -60,7 +59,6 @@ struct pkg_operations {
alpm_list_t *(*get_conflicts) (alpm_pkg_t *); alpm_list_t *(*get_conflicts) (alpm_pkg_t *);
alpm_list_t *(*get_provides) (alpm_pkg_t *); alpm_list_t *(*get_provides) (alpm_pkg_t *);
alpm_list_t *(*get_replaces) (alpm_pkg_t *); alpm_list_t *(*get_replaces) (alpm_pkg_t *);
alpm_list_t *(*get_deltas) (alpm_pkg_t *);
alpm_filelist_t *(*get_files) (alpm_pkg_t *); alpm_filelist_t *(*get_files) (alpm_pkg_t *);
alpm_list_t *(*get_backup) (alpm_pkg_t *); alpm_list_t *(*get_backup) (alpm_pkg_t *);
@ -69,11 +67,6 @@ struct pkg_operations {
int (*changelog_close) (const alpm_pkg_t *, void *); int (*changelog_close) (const alpm_pkg_t *, void *);
int (*force_load) (alpm_pkg_t *); int (*force_load) (alpm_pkg_t *);
/* still to add:
* checkmd5sum() ?
* compute_requiredby()
*/
}; };
/** The standard package operations struct. get fields directly from the /** The standard package operations struct. get fields directly from the

View file

@ -511,7 +511,7 @@ int SYMEXPORT alpm_pkg_check_pgp_signature(alpm_pkg_t *pkg,
ASSERT(siglist != NULL, RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1)); ASSERT(siglist != NULL, RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1));
pkg->handle->pm_errno = 0; pkg->handle->pm_errno = 0;
return _alpm_gpgme_checksig(pkg->handle, alpm_pkg_get_filename(pkg), return _alpm_gpgme_checksig(pkg->handle, pkg->filename,
pkg->base64_sig, siglist); pkg->base64_sig, siglist);
} }

View file

@ -284,7 +284,6 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs,
*/ */
static int compute_download_size(alpm_pkg_t *newpkg) static int compute_download_size(alpm_pkg_t *newpkg)
{ {
const char *fname;
char *fpath; char *fpath;
off_t size = 0; off_t size = 0;
alpm_handle_t *handle = newpkg->handle; alpm_handle_t *handle = newpkg->handle;
@ -295,9 +294,8 @@ static int compute_download_size(alpm_pkg_t *newpkg)
return 0; return 0;
} }
fname = alpm_pkg_get_filename(newpkg); ASSERT(newpkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
ASSERT(fname != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1)); fpath = _alpm_filecache_find(handle, newpkg->filename);
fpath = _alpm_filecache_find(handle, fname);
if(fpath) { if(fpath) {
FREE(fpath); FREE(fpath);
@ -305,10 +303,8 @@ static int compute_download_size(alpm_pkg_t *newpkg)
} else if(handle->usedelta) { } else if(handle->usedelta) {
off_t dltsize; off_t dltsize;
dltsize = _alpm_shortest_delta_path(handle, dltsize = _alpm_shortest_delta_path(handle, newpkg->deltas,
alpm_pkg_get_deltas(newpkg), newpkg->filename, &newpkg->delta_path);
alpm_pkg_get_filename(newpkg),
&newpkg->delta_path);
if(newpkg->delta_path && (dltsize < newpkg->size * MAX_DELTA_RATIO)) { if(newpkg->delta_path && (dltsize < newpkg->size * MAX_DELTA_RATIO)) {
_alpm_log(handle, ALPM_LOG_DEBUG, "using delta size\n"); _alpm_log(handle, ALPM_LOG_DEBUG, "using delta size\n");
@ -934,7 +930,6 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
for(i = trans->add; i; i = i->next, current++) { for(i = trans->add; i; i = i->next, current++) {
alpm_pkg_t *spkg = i->data; alpm_pkg_t *spkg = i->data;
const char *filename;
char *filepath; char *filepath;
alpm_siglevel_t level; alpm_siglevel_t level;
int percent = (int)(((double)current_bytes / total_bytes) * 100); int percent = (int)(((double)current_bytes / total_bytes) * 100);
@ -946,8 +941,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
} }
current_bytes += spkg->size; current_bytes += spkg->size;
filename = alpm_pkg_get_filename(spkg); filepath = _alpm_filecache_find(handle, spkg->filename);
filepath = _alpm_filecache_find(handle, filename);
alpm_db_t *sdb = alpm_pkg_get_db(spkg); alpm_db_t *sdb = alpm_pkg_get_db(spkg);
level = alpm_db_get_siglevel(sdb); level = alpm_db_get_siglevel(sdb);
@ -960,7 +954,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
if(!pkgfile) { if(!pkgfile) {
prompt_to_delete(handle, filepath, handle->pm_errno); prompt_to_delete(handle, filepath, handle->pm_errno);
errors++; errors++;
*data = alpm_list_add(*data, strdup(filename)); *data = alpm_list_add(*data, strdup(spkg->filename));
FREE(filepath); FREE(filepath);
continue; continue;
} }