summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2007-03-03 08:13:59 +0000
committerAaron Griffin <aaron@archlinux.org>2007-03-03 08:13:59 +0000
commit7f5dada8851c3b40ba44ed92e46315cefa9006b2 (patch)
tree402349c1d0cb2e82a4606872954b4d46e4df10ed /lib/libalpm
parenta0dbade77420f6e83be1406ae67a99e337ce57ec (diff)
Big commit this time:
* Moved entirely to alpm_pkg_get_* accessors, to read data on demand * Mostly removed the INFRQ_ parameters from outside the be_files backend (making the backend more extensible in the long run) * packages created from _alpm_db_scan now have the db and origin set (making accessors actually work for these packages) * removed _alpm_db_ensure_pkgcache * totally revamped the _alpm_checkconflicts function, making it cleaner and easier to read (and thus fix in the long run) - maintainable code ftw NOTE: feel free to rename the functions... I couldn't think of anything better * removed an extra loop in sync.c:find_replacements - no sense in looping over an entire DB while strcmp'ing the name, when we have get_pkgfromcache Other: * package struct "license" -> "licenses" * Created _alpm_sync_find (duplicate code in some places, find_pkginsync * Minor const correctness changes along the way * fixed a couple extra '/' pathing issues (non-issues really) * removed a duplicate pkg_cmp function
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/add.c60
-rw-r--r--lib/libalpm/alpm.c106
-rw-r--r--lib/libalpm/alpm.h2
-rw-r--r--lib/libalpm/alpm_list.c2
-rw-r--r--lib/libalpm/alpm_list.h2
-rw-r--r--lib/libalpm/be_files.c17
-rw-r--r--lib/libalpm/cache.c82
-rw-r--r--lib/libalpm/cache.h4
-rw-r--r--lib/libalpm/conflict.c341
-rw-r--r--lib/libalpm/db.c16
-rw-r--r--lib/libalpm/db.h2
-rw-r--r--lib/libalpm/deps.c124
-rw-r--r--lib/libalpm/package.c67
-rw-r--r--lib/libalpm/package.h2
-rw-r--r--lib/libalpm/provide.c2
-rw-r--r--lib/libalpm/remove.c50
-rw-r--r--lib/libalpm/sync.c255
-rw-r--r--lib/libalpm/sync.h3
-rw-r--r--lib/libalpm/trans.c34
-rw-r--r--lib/libalpm/util.c28
-rw-r--r--lib/libalpm/util.h16
-rw-r--r--lib/libalpm/versioncmp.c8
22 files changed, 651 insertions, 572 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 220c1d8a..64686ed2 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -260,7 +260,7 @@ int _alpm_add_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
_alpm_log(PM_LOG_DEBUG, _("cleaning up"));
for (lp=trans->packages; lp!=NULL; lp=lp->next) {
info=(pmpkg_t *)lp->data;
- for (rmlist=info->removes; rmlist!=NULL; rmlist=rmlist->next) {
+ for (rmlist = alpm_pkg_get_removes(info); rmlist; rmlist = rmlist->next) {
snprintf(rm_fname, PATH_MAX, "%s%s", handle->root, (char *)rmlist->data);
remove(rm_fname);
}
@@ -354,7 +354,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
newpkg->reason = alpm_pkg_get_reason(local);
/* pre_upgrade scriptlet */
- if(newpkg->scriptlet && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
+ if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
_alpm_runscriptlet(handle->root, newpkg->data, "pre_upgrade", newpkg->version, oldpkg->version, trans);
}
} else {
@@ -364,7 +364,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
_alpm_log(PM_LOG_DEBUG, _("adding package %s-%s"), newpkg->name, newpkg->version);
/* pre_install scriptlet */
- if(newpkg->scriptlet && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
+ if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
_alpm_runscriptlet(handle->root, newpkg->data, "pre_install", newpkg->version, NULL, trans);
}
}
@@ -400,9 +400,10 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
* old, we cover all bases, including backup=() locations changing hands.
* But is this viable? */
alpm_list_t *old_noupgrade = alpm_list_strdup(handle->noupgrade);
- for(b = newpkg->backup; b; b = b->next) {
- _alpm_log(PM_LOG_DEBUG, _("adding %s to the NoUpgrade array temporarilly"), (char *)b->data);
- handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(b->data));
+ for(b = alpm_pkg_get_backup(newpkg); b; b = b->next) {
+ const char *backup = b->data;
+ _alpm_log(PM_LOG_DEBUG, _("adding %s to the NoUpgrade array temporarilly"), backup);
+ handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(backup));
}
int ret = _alpm_remove_commit(tr, db);
@@ -491,7 +492,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
/* if a file is in NoExtract then we never extract it */
if(alpm_list_find_str(handle->noextract, entryname)) {
_alpm_log(PM_LOG_DEBUG, _("%s is in NoExtract, skipping extraction"), entryname);
- alpm_logaction(_("notice: %s is in NoExtract -- skipping extraction"), entryname);
+ alpm_logaction(_("%s is in NoExtract, skipping extraction"), entryname);
archive_read_data_skip(archive);
continue;
}
@@ -508,10 +509,10 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
/* it does, is it a backup=() file?
* always check the newpkg first, so when we do add a backup=() file,
* we don't have to wait a full upgrade cycle */
- needbackup = alpm_list_find_str(newpkg->backup, entryname);
+ needbackup = alpm_list_find_str(alpm_pkg_get_backup(newpkg), entryname);
if(is_upgrade) {
- hash_orig = _alpm_needbackup(entryname, oldpkg->backup);
+ hash_orig = _alpm_needbackup(entryname, alpm_pkg_get_backup(oldpkg));
if(hash_orig) {
needbackup = 1;
}
@@ -561,9 +562,9 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
hash_pkg = _alpm_SHAFile(tempfile);
}
- /* append the new md5 or sha1 hash to it's respective entry in newpkg->backup
+ /* append the new md5 or sha1 hash to it's respective entry in newpkg's backup
* (it will be the new orginal) */
- for(lp = newpkg->backup; lp; lp = lp->next) {
+ for(lp = alpm_pkg_get_backup(newpkg); lp; lp = lp->next) {
if(!lp->data || strcmp(lp->data, entryname) != 0) {
continue;
}
@@ -699,8 +700,8 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
errors++;
}
- /* calculate an hash if this is in newpkg->backup */
- for(lp = newpkg->backup; lp; lp = lp->next) {
+ /* calculate an hash if this is in newpkg's backup */
+ for(lp = alpm_pkg_get_backup(newpkg); lp; lp = lp->next) {
char *backup = NULL, *hash = NULL;
int backup_len = strlen(lp->data) + 2; /* tab char and null byte */
@@ -760,7 +761,8 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
for(prov = provdiff; prov; prov = prov->next) {
const char *provname = prov->data;
_alpm_log(PM_LOG_DEBUG, _("provision '%s' has been removed from package %s (%s => %s)"),
- provname, oldpkg->name, oldpkg->version, newpkg->version);
+ provname, alpm_pkg_get_name(oldpkg),
+ alpm_pkg_get_version(oldpkg), alpm_pkg_get_version(newpkg));
alpm_list_t *p = _alpm_db_whatprovides(handle->db_local, provname);
if(p) {
@@ -769,15 +771,18 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
* provision, we'll use the FIRST for now.
* TODO figure out a way to find a "correct" provision */
pmpkg_t *provpkg = p->data;
- _alpm_log(PM_LOG_DEBUG, _("updating '%s' due to provision change (%s)"), provpkg->name, provname);
+ const char *pkgname = alpm_pkg_get_name(provpkg);
+ _alpm_log(PM_LOG_DEBUG, _("updating '%s' due to provision change (%s)"), pkgname, provname);
_alpm_pkg_update_requiredby(provpkg);
+
if(_alpm_db_write(db, provpkg, INFRQ_DEPENDS)) {
- _alpm_log(PM_LOG_ERROR, _("could not update provision '%s' from '%s'"), provname, provpkg->name);
- alpm_logaction(_("could not update provision '%s' from '%s'"), provname, provpkg->name);
+ _alpm_log(PM_LOG_ERROR, _("could not update provision '%s' from '%s'"), provname, pkgname);
+ alpm_logaction(_("could not update provision '%s' from '%s'"), provname, pkgname);
RET_ERR(PM_ERR_DB_WRITE, -1);
}
}
}
+ alpm_list_free(provdiff);
/* make an install date (in UTC) */
time_t t = time(NULL);
@@ -790,31 +795,36 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
if(_alpm_db_write(db, newpkg, INFRQ_ALL)) {
_alpm_log(PM_LOG_ERROR, _("could not update database entry %s-%s"),
- newpkg->name, newpkg->version);
+ alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg));
alpm_logaction(_("could not update database entry %s-%s"),
- newpkg->name, newpkg->version);
+ alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg));
RET_ERR(PM_ERR_DB_WRITE, -1);
}
if(_alpm_db_add_pkgincache(db, newpkg) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not add entry '%s' in cache"), newpkg->name);
+ _alpm_log(PM_LOG_ERROR, _("could not add entry '%s' in cache"),
+ alpm_pkg_get_name(newpkg));
}
/* update dependency packages' REQUIREDBY fields */
_alpm_trans_update_depends(trans, newpkg);
PROGRESS(trans, (is_upgrade ? PM_TRANS_PROGRESS_UPGRADE_START : PM_TRANS_PROGRESS_ADD_START),
- newpkg->name, 100, pkg_count, (pkg_count - targ_count +1));
+ alpm_pkg_get_name(newpkg), 100, pkg_count, (pkg_count - targ_count +1));
EVENT(trans, PM_TRANS_EVT_EXTRACT_DONE, NULL, NULL);
/* run the post-install script if it exists */
- if(newpkg->scriptlet && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
+ if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
char pm_install[PATH_MAX];
- snprintf(pm_install, PATH_MAX, "%s%s/%s/%s-%s/install", handle->root, handle->dbpath, db->treename, newpkg->name, newpkg->version);
+ snprintf(pm_install, PATH_MAX, "%s%s/%s/%s-%s/install", handle->root, handle->dbpath, db->treename,
+ alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg));
if(is_upgrade) {
- _alpm_runscriptlet(handle->root, pm_install, "post_upgrade", newpkg->version, oldpkg ? oldpkg->version : NULL, trans);
+ _alpm_runscriptlet(handle->root, pm_install, "post_upgrade",
+ alpm_pkg_get_version(newpkg), oldpkg ? alpm_pkg_get_version(oldpkg) : NULL,
+ trans);
} else {
- _alpm_runscriptlet(handle->root, pm_install, "post_install", newpkg->version, NULL, trans);
+ _alpm_runscriptlet(handle->root, pm_install, "post_install",
+ alpm_pkg_get_version(newpkg), NULL, trans);
}
}
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index f01e0da5..96ad3416 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -302,13 +302,12 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
snprintf(path, PATH_MAX, "%s%s/%s" PM_EXT_DB, handle->root, handle->dbpath, db->treename);
/* remove the old dir */
- _alpm_log(PM_LOG_DEBUG, _("flushing database %s/%s"), handle->dbpath, db->treename);
- for(lp = _alpm_db_get_pkgcache(db, INFRQ_BASE); lp; lp = lp->next) {
- if(_alpm_db_remove(db, lp->data) == -1) {
- if(lp->data) {
- _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s/%s"), db->treename,
- ((pmpkg_t *)lp->data)->name);
- }
+ _alpm_log(PM_LOG_DEBUG, _("flushing database %s%s"), handle->dbpath, db->treename);
+ for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
+ pmpkg_t *pkg = lp->data;
+ if(pkg && _alpm_db_remove(db, pkg) == -1) {
+ _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s%s"), db->treename,
+ alpm_pkg_get_name(pkg));
RET_ERR(PM_ERR_DB_REMOVE, -1);
}
}
@@ -354,7 +353,7 @@ alpm_list_t SYMEXPORT *alpm_db_getpkgcache(pmdb_t *db)
ASSERT(handle != NULL, return(NULL));
ASSERT(db != NULL, return(NULL));
- return(_alpm_db_get_pkgcache(db, INFRQ_BASE));
+ return(_alpm_db_get_pkgcache(db));
}
/** Get the list of packages that a package provides
@@ -472,21 +471,21 @@ int alpm_pkg_checksha1sum(pmpkg_t *pkg)
snprintf(path, PATH_MAX, "%s%s/%s-%s" PM_EXT_PKG,
handle->root, handle->cachedir,
- pkg->name, pkg->version);
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
sha1sum = _alpm_SHAFile(path);
if(sha1sum == NULL) {
_alpm_log(PM_LOG_ERROR, _("could not get sha1sum for package %s-%s"),
- pkg->name, pkg->version);
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
pm_errno = PM_ERR_NOT_A_FILE;
retval = -1;
} else {
if(strcmp(sha1sum, alpm_pkg_get_sha1sum(pkg)) == 0) {
_alpm_log(PM_LOG_DEBUG, _("sha1sums for package %s-%s match"),
- pkg->name, pkg->version);
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
} else {
_alpm_log(PM_LOG_ERROR, _("sha1sums do not match for package %s-%s"),
- pkg->name, pkg->version);
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
pm_errno = PM_ERR_PKG_INVALID;
retval = -1;
}
@@ -516,21 +515,21 @@ int alpm_pkg_checkmd5sum(pmpkg_t *pkg)
snprintf(path, PATH_MAX, "%s%s/%s-%s" PM_EXT_PKG,
handle->root, handle->cachedir,
- pkg->name, pkg->version);
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
md5sum = _alpm_MDFile(path);
if(md5sum == NULL) {
_alpm_log(PM_LOG_ERROR, _("could not get md5sum for package %s-%s"),
- pkg->name, pkg->version);
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
pm_errno = PM_ERR_NOT_A_FILE;
retval = -1;
} else {
if(strcmp(md5sum, alpm_pkg_get_md5sum(pkg)) == 0) {
_alpm_log(PM_LOG_DEBUG, _("md5sums for package %s-%s match"),
- pkg->name, pkg->version);
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
} else {
_alpm_log(PM_LOG_ERROR, _("md5sums do not match for package %s-%s"),
- pkg->name, pkg->version);
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
pm_errno = PM_ERR_PKG_INVALID;
retval = -1;
}
@@ -1071,9 +1070,8 @@ int SYMEXPORT alpm_parse_config(char *file, alpm_cb_db_register callback, const
* solution made for -Qu operation */
alpm_list_t *alpm_get_upgrades()
{
- int found = 0;
alpm_list_t *syncpkgs = NULL;
- alpm_list_t *i, *j, *k;
+ alpm_list_t *i, *j, *k, *m;
ALPM_LOG_FUNC;
@@ -1081,36 +1079,35 @@ alpm_list_t *alpm_get_upgrades()
/* check for "recommended" package replacements */
_alpm_log(PM_LOG_DEBUG, _("checking for package replacements"));
for(i = handle->dbs_sync; i; i = i->next) {
- for(j = _alpm_db_get_pkgcache(i->data, INFRQ_DESC); j; j = j->next) {
+ for(j = _alpm_db_get_pkgcache(i->data); j; j = j->next) {
pmpkg_t *spkg = j->data;
- for(k = spkg->replaces; k; k = k->next) {
- alpm_list_t *m;
- for(m = _alpm_db_get_pkgcache(handle->db_local, INFRQ_BASE); m; m = m->next) {
+
+ for(k = alpm_pkg_get_replaces(spkg); k; k = k->next) {
+
+ for(m = _alpm_db_get_pkgcache(handle->db_local); m; m = m->next) {
pmpkg_t *lpkg = m->data;
- if(strcmp(k->data, lpkg->name) == 0) {
- _alpm_log(PM_LOG_DEBUG, _("checking replacement '%s' for package '%s'"), k->data, spkg->name);
- if(alpm_list_find_str(handle->ignorepkg, lpkg->name)) {
+
+ if(strcmp(k->data, alpm_pkg_get_name(lpkg)) == 0) {
+ _alpm_log(PM_LOG_DEBUG, _("checking replacement '%s' for package '%s'"), k->data,
+ alpm_pkg_get_name(spkg));
+ if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(lpkg))) {
_alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (to be replaced by %s-%s)"),
- lpkg->name, lpkg->version, spkg->name, spkg->version);
+ alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg),
+ alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
} else {
/* assume all replaces=() packages are accepted */
pmsyncpkg_t *sync = NULL;
- pmpkg_t *dummy = _alpm_pkg_new(lpkg->name, NULL);
+ pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(lpkg), NULL);
if(dummy == NULL) {
pm_errno = PM_ERR_MEMORY;
goto error;
}
- dummy->requiredby = alpm_list_strdup(lpkg->requiredby);
- /* check if spkg->name is already in the packages list. */
- alpm_list_t *s;
- for(s = syncpkgs; s && !found; s = s->next) {
- sync = i->data;
- if(sync && !strcmp(sync->pkg->name, spkg->name)) {
- found = 1;
- }
- }
+ dummy->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(lpkg));
+
+ pmsyncpkg_t *syncpkg;
+ syncpkg = _alpm_sync_find(syncpkgs, alpm_pkg_get_name(spkg));
- if(found) {
+ if(syncpkg) {
/* found it -- just append to the replaces list */
sync->data = alpm_list_add(sync->data, dummy);
} else {
@@ -1125,7 +1122,8 @@ alpm_list_t *alpm_get_upgrades()
syncpkgs = alpm_list_add(syncpkgs, sync);
}
_alpm_log(PM_LOG_DEBUG, _("%s-%s elected for upgrade (to be replaced by %s-%s)"),
- lpkg->name, lpkg->version, spkg->name, spkg->version);
+ alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg),
+ alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
}
break;
}
@@ -1135,17 +1133,17 @@ alpm_list_t *alpm_get_upgrades()
}
/* now do normal upgrades */
- for(i = _alpm_db_get_pkgcache(handle->db_local, INFRQ_BASE); i; i = i->next) {
+ for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = i->next) {
int replace=0;
pmpkg_t *local = i->data;
pmpkg_t *spkg = NULL;
pmsyncpkg_t *sync;
for(j = handle->dbs_sync; !spkg && j; j = j->next) {
- spkg = _alpm_db_get_pkgfromcache(j->data, local->name);
+ spkg = _alpm_db_get_pkgfromcache(j->data, alpm_pkg_get_name(local));
}
if(spkg == NULL) {
- _alpm_log(PM_LOG_DEBUG, _("'%s' not found in sync db -- skipping"), local->name);
+ _alpm_log(PM_LOG_DEBUG, _("'%s' not found in sync db -- skipping"), alpm_pkg_get_name(local));
continue;
}
@@ -1153,32 +1151,28 @@ alpm_list_t *alpm_get_upgrades()
for(j = syncpkgs; j && !replace; j=j->next) {
sync = j->data;
if(sync->type == PM_SYNC_TYPE_REPLACE) {
- if(_alpm_pkg_find(spkg->name, sync->data)) {
+ if(_alpm_pkg_find(alpm_pkg_get_name(spkg), sync->data)) {
replace=1;
}
}
}
if(replace) {
_alpm_log(PM_LOG_DEBUG, _("'%s' is already elected for removal -- skipping"),
- local->name);
+ alpm_pkg_get_name(local));
continue;
}
if(alpm_pkg_compare_versions(local, spkg)) {
- _alpm_log(PM_LOG_DEBUG, _("%s-%s elected for upgrade (%s => %s)"),
- local->name, local->version, local->version, spkg->version);
- alpm_list_t *s;
- pmsyncpkg_t *sync = NULL;
- found = 0;
- for(s = syncpkgs; s && !found; s = s->next) {
- sync = s->data;
- if(sync && strcmp(sync->pkg->name, local->name) == 0) {
- found = 1;
- }
- }
+ _alpm_log(PM_LOG_DEBUG, _("%s elected for upgrade (%s => %s)"),
+ alpm_pkg_get_name(local), alpm_pkg_get_version(local),
+ alpm_pkg_get_version(spkg));
+
+ pmsyncpkg_t *syncpkg;
+ syncpkg = _alpm_sync_find(syncpkgs, alpm_pkg_get_name(local));
- if(!found) {
- pmpkg_t *dummy = _alpm_pkg_new(local->name, local->version);
+ if(!syncpkg) {
+ pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(local),
+ alpm_pkg_get_version(local));
if(dummy == NULL) {
goto error;
}
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 9a093a97..9308efd8 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -343,7 +343,7 @@ typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
void *, int *);
/* Transaction Progress callback */
-typedef void (*alpm_trans_cb_progress)(pmtransprog_t, char *, int, int, int);
+typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, int, int);
pmtranstype_t alpm_trans_get_type();
unsigned int alpm_trans_get_flags();
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index 36517fd2..0737fc89 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -236,7 +236,7 @@ alpm_list_t* alpm_list_msort(alpm_list_t *list, int n, alpm_list_fn_cmp fn)
* @param data output parameter containing the data member of the item removed
* @return the resultant list, or NULL on failure
*/
-alpm_list_t *alpm_list_remove(alpm_list_t *haystack, void *needle, alpm_list_fn_cmp fn, void **data)
+alpm_list_t *alpm_list_remove(alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn, void **data)
{ /* TODO I modified this to remove ALL matching items. Do we need a remove_first? */
alpm_list_t *i = haystack, *tmp = NULL;
diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h
index f3a7c6ef..214deea4 100644
--- a/lib/libalpm/alpm_list.h
+++ b/lib/libalpm/alpm_list.h
@@ -48,7 +48,7 @@ alpm_list_t *alpm_list_add(alpm_list_t *list, void *data);
alpm_list_t *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_list_fn_cmp fn);
alpm_list_t *alpm_list_mmerge(alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn);
alpm_list_t *alpm_list_msort(alpm_list_t *list, int n, alpm_list_fn_cmp fn);
-alpm_list_t *alpm_list_remove(alpm_list_t *haystack, void *needle, alpm_list_fn_cmp fn, void **data);
+alpm_list_t *alpm_list_remove(alpm_list_t *haystack, const void *needle, alpm_list_fn_cmp fn, void **data);
alpm_list_t *alpm_list_remove_node(alpm_list_t *node);
alpm_list_t *alpm_list_remove_dupes(alpm_list_t *list);
alpm_list_t *alpm_list_strdup(alpm_list_t *list);
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index ac268788..a847af05 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -106,7 +106,7 @@ void _alpm_db_rewind(pmdb_t *db)
rewinddir(db->handle);
}
-pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target, pmdbinfrq_t inforeq)
+pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target)
{
struct dirent *ent = NULL;
struct stat sbuf;
@@ -183,9 +183,14 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target, pmdbinfrq_t inforeq)
_alpm_log(PM_LOG_ERROR, _("invalid name for dabatase entry '%s'"), ent->d_name);
return(NULL);
}
- if(_alpm_db_read(db, pkg, inforeq) == -1) {
+
+ /* explicitly read with only 'BASE' data, accessors will handle the rest */
+ if(_alpm_db_read(db, pkg, INFRQ_BASE) == -1) {
/* TODO removed corrupt entry from the FS here */
FREEPKG(pkg);
+ } else {
+ pkg->data = db;
+ pkg->origin = PKG_FROM_CACHE;
}
}
@@ -298,7 +303,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
_alpm_strtrim(info->url);
} else if(!strcmp(line, "%LICENSE%")) {
while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) {
- info->license = alpm_list_add(info->license, strdup(line));
+ info->licenses = alpm_list_add(info->licenses, strdup(line));
}
} else if(!strcmp(line, "%ARCH%")) {
if(fgets(info->arch, sizeof(info->arch), fp) == NULL) {
@@ -527,9 +532,9 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
fprintf(fp, "%%URL%%\n"
"%s\n\n", info->url);
}
- if(info->license) {
+ if(info->licenses) {
fputs("%LICENSE%\n", fp);
- for(lp = info->license; lp; lp = lp->next) {
+ for(lp = info->licenses; lp; lp = lp->next) {
fprintf(fp, "%s\n", (char *)lp->data);
}
fprintf(fp, "\n");
@@ -687,7 +692,7 @@ int _alpm_db_remove(pmdb_t *db, pmpkg_t *info)
RET_ERR(PM_ERR_DB_NULL, -1);
}
- snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, info->version);
+ snprintf(path, PATH_MAX, "%s%s-%s", db->path, info->name, info->version);
if(_alpm_rmrf(path) == -1) {
return(-1);
}
diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c
index 74299061..75100283 100644
--- a/lib/libalpm/cache.c
+++ b/lib/libalpm/cache.c
@@ -41,12 +41,10 @@
/* Returns a new package cache from db.
* It frees the cache if it already exists.
*/
-int _alpm_db_load_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel)
+int _alpm_db_load_pkgcache(pmdb_t *db)
{
pmpkg_t *info;
int count = 0;
- /* The group cache needs INFRQ_DESC as well */
- /* pmdbinfrq_t infolevel = INFRQ_DEPENDS | INFRQ_DESC;*/
ALPM_LOG_FUNC;
@@ -56,12 +54,13 @@ int _alpm_db_load_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel)
_alpm_db_free_pkgcache(db);
- _alpm_log(PM_LOG_DEBUG, _("loading package cache (infolevel=%#x) for repository '%s'"),
- infolevel, db->treename);
+ _alpm_log(PM_LOG_DEBUG, _("loading package cache for repository '%s'"),
+ db->treename);
_alpm_db_rewind(db);
- while((info = _alpm_db_scan(db, NULL, infolevel)) != NULL) {
- _alpm_log(PM_LOG_FUNCTION, _("adding '%s' to package cache for db '%s'"), info->name, db->treename);
+ while((info = _alpm_db_scan(db, NULL)) != NULL) {
+ _alpm_log(PM_LOG_FUNCTION, _("adding '%s' to package cache for db '%s'"),
+ alpm_pkg_get_name(info), db->treename);
info->origin = PKG_FROM_CACHE;
info->data = db;
/* add to the collection */
@@ -91,7 +90,7 @@ void _alpm_db_free_pkgcache(pmdb_t *db)
}
}
-alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel)
+alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db)
{
ALPM_LOG_FUNC;
@@ -99,44 +98,16 @@ alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel)
return(NULL);
}
- if(db->pkgcache == NULL) {
- _alpm_db_load_pkgcache(db, infolevel);
+ if(!db->pkgcache) {
+ _alpm_db_load_pkgcache(db);
}
- _alpm_db_ensure_pkgcache(db, infolevel);
-
+ /* hmmm, still NULL ?*/
if(!db->pkgcache) {
_alpm_log(PM_LOG_DEBUG, _("error: pkgcache is NULL for db '%s'"), db->treename);
}
- return(db->pkgcache);
-}
-
-int _alpm_db_ensure_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel)
-{
- int reloaded = 0;
- /* for each pkg, check and reload if the requested
- * info is not already cached
- */
-
- ALPM_LOG_FUNC;
- alpm_list_t *p;
- for(p = db->pkgcache; p; p = p->next) {
- pmpkg_t *pkg = (pmpkg_t *)p->data;
- if(infolevel != INFRQ_BASE && !(pkg->infolevel & infolevel)) {
- if(_alpm_db_read(db, pkg, infolevel) == -1) {
- /* TODO should we actually remove from the filesystem here as well? */
- _alpm_db_remove_pkgfromcache(db, pkg);
- } else {
- reloaded = 1;
- }
- }
- }
- if(reloaded) {
- _alpm_log(PM_LOG_DEBUG, _("package cache reloaded (infolevel=%#x) for repository '%s'"),
- infolevel, db->treename);
- }
- return(0);
+ return(db->pkgcache);
}
int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
@@ -153,7 +124,8 @@ int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
if(newpkg == NULL) {
return(-1);
}
- _alpm_log(PM_LOG_DEBUG, _("adding entry '%s' in '%s' cache"), newpkg->name, db->treename);
+ _alpm_log(PM_LOG_DEBUG, _("adding entry '%s' in '%s' cache"),
+ alpm_pkg_get_name(newpkg), db->treename);
db->pkgcache = alpm_list_add_sorted(db->pkgcache, newpkg, _alpm_pkg_cmp);
_alpm_db_free_grpcache(db);
@@ -172,14 +144,18 @@ int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
return(-1);
}
+ _alpm_log(PM_LOG_DEBUG, _("removing entry '%s' from '%s' cache"),
+ alpm_pkg_get_name(pkg), db->treename);
+
db->pkgcache = alpm_list_remove(db->pkgcache, pkg, _alpm_pkg_cmp, &vdata);
data = vdata;
if(data == NULL) {
/* package not found */
+ _alpm_log(PM_LOG_DEBUG, _("cannot remove entry '%s' from '%s' cache: not found"),
+ alpm_pkg_get_name(pkg), db->treename);
return(-1);
}
- _alpm_log(PM_LOG_DEBUG, _("removing entry '%s' from '%s' cache"), pkg->name, db->treename);
FREEPKG(data);
_alpm_db_free_grpcache(db);
@@ -195,7 +171,7 @@ pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, const char *target)
return(NULL);
}
- alpm_list_t *pkgcache = _alpm_db_get_pkgcache(db, INFRQ_BASE);
+ alpm_list_t *pkgcache = _alpm_db_get_pkgcache(db);
if(!pkgcache) {
_alpm_log(PM_LOG_DEBUG, _("error: failed to get '%s' from NULL pkgcache"), target);
return(NULL);
@@ -217,21 +193,26 @@ int _alpm_db_load_grpcache(pmdb_t *db)
}
if(db->pkgcache == NULL) {
- _alpm_db_load_pkgcache(db, INFRQ_DESC);
+ _alpm_db_load_pkgcache(db);
}
_alpm_log(PM_LOG_DEBUG, _("loading group cache for repository '%s'"), db->treename);
- for(lp = _alpm_db_get_pkgcache(db, INFRQ_DESC); lp; lp = lp->next) {
+ for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
alpm_list_t *i;
pmpkg_t *pkg = lp->data;
- for(i = pkg->groups; i; i = i->next) {
+ for(i = alpm_pkg_get_groups(pkg); i; i = i->next) {
if(!alpm_list_find_str(db->grpcache, i->data)) {
pmgrp_t *grp = _alpm_grp_new();
- STRNCPY(grp->name, (char *)i->data, GRP_NAME_LEN);
- grp->packages = alpm_list_add_sorted(grp->packages, pkg->name, _alpm_grp_cmp);
+ strncpy(grp->name, i->data, GRP_NAME_LEN);
+ grp->name[GRP_NAME_LEN-1] = '\0';
+ grp->packages = alpm_list_add_sorted(grp->packages,
+ /* gross signature forces us to
+ * discard const */
+ (void *)alpm_pkg_get_name(pkg),
+ _alpm_grp_cmp);
db->grpcache = alpm_list_add_sorted(db->grpcache, grp, _alpm_grp_cmp);
} else {
alpm_list_t *j;
@@ -240,8 +221,9 @@ int _alpm_db_load_grpcache(pmdb_t *db)
pmgrp_t *grp = j->data;
if(strcmp(grp->name, i->data) == 0) {
- if(!alpm_list_find_str(grp->packages, pkg->name)) {
- grp->packages = alpm_list_add_sorted(grp->packages, (char *)pkg->name, _alpm_grp_cmp);
+ const char *pkgname = alpm_pkg_get_name(pkg);
+ if(!alpm_list_find_str(grp->packages, pkgname)) {
+ grp->packages = alpm_list_add_sorted(grp->packages, (void *)pkgname, _alpm_grp_cmp);
}
}
}
diff --git a/lib/libalpm/cache.h b/lib/libalpm/cache.h
index 7efae5b8..fa1fef32 100644
--- a/lib/libalpm/cache.h
+++ b/lib/libalpm/cache.h
@@ -27,11 +27,11 @@
#include "package.h"
/* packages */
-int _alpm_db_load_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel);
+int _alpm_db_load_pkgcache(pmdb_t *db);
void _alpm_db_free_pkgcache(pmdb_t *db);
int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg);
int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg);
-alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel);
+alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db);
int _alpm_db_ensure_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel);
pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, const char *target);
/* groups */
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 9a164dbe..d8843bda 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -46,168 +46,218 @@
#include "deps.h"
#include "conflict.h"
-/* Returns a alpm_list_t* of pmdepmissing_t pointers.
+
+/** See if potential conflict 'name' matches package 'pkg'
+ * @param target the name of the parent package we're checking
+ * @param depname the name of the dependency we're checking
+ * @param pkg the package to check
+ * @param conflict the name of the possible conflict
+ * @return A depmissing struct indicating the conflict
+ * @note The first two paramters are here to simplify the addition
+ * of new 'depmiss' objects
*
- * conflicts are always name only
+ * TODO WTF is a 'depmissing' doing indicating a conflict??
*/
-alpm_list_t *_alpm_checkconflicts(pmdb_t *db, alpm_list_t *packages)
+static pmdepmissing_t *does_conflict(const char *target, const char *depname,
+ pmpkg_t *pkg, const char *conflict)
+{
+ alpm_list_t *i;
+
+ /* check the actual package name, easy */
+ if(strcmp(alpm_pkg_get_name(pkg), conflict) == 0) {
+ _alpm_log(PM_LOG_DEBUG, _(" found conflict '%s' : package '%s'"), conflict, target);
+ return(_alpm_depmiss_new(target, PM_DEP_TYPE_CONFLICT,
+ PM_DEP_MOD_ANY, depname, NULL));
+ } else {
+ /* check what this package provides, harder */
+ for(i = alpm_pkg_get_provides(pkg); i; i = i->next) {
+ const char *provision = i->data;
+
+ if(strcmp(provision, conflict) == 0) {
+ _alpm_log(PM_LOG_DEBUG, _(" found conflict '%s' : package '%s' provides '%s'"),
+ conflict, target, provision);
+ return(_alpm_depmiss_new(target, PM_DEP_TYPE_CONFLICT,
+ PM_DEP_MOD_ANY, depname, NULL));
+ }
+ }
+ }
+ return(NULL); /* not a conflict */
+}
+
+static alpm_list_t *chk_pkg_vs_db(alpm_list_t *baddeps, pmpkg_t *pkg, pmdb_t *db)
{
- pmpkg_t *info = NULL;
- alpm_list_t *i, *j, *k;
- alpm_list_t *baddeps = NULL;
pmdepmissing_t *miss = NULL;
+ const char *pkgname;
+ alpm_list_t *i, *j;
- ALPM_LOG_FUNC;
+ pkgname = alpm_pkg_get_name(pkg);
- if(db == NULL) {
- return(NULL);
- }
+ for(i = alpm_pkg_get_conflicts(pkg); i; i = i->next) {
+ const char *conflict = i->data;
- for(i = packages; i; i = i->next) {
- pmpkg_t *tp = i->data;
- if(tp == NULL) {
+ if(strcmp(pkgname, conflict) == 0) {
+ /* a package cannot conflict with itself -- that's just not nice */
+ _alpm_log(PM_LOG_DEBUG, _("package '%s' conflicts with itself - packaging error"),
+ pkgname);
continue;
}
- for(j = tp->conflicts; j; j = j->next) {
- if(!strcmp(tp->name, j->data)) {
- /* a package cannot conflict with itself -- that's just not nice */
+ /* CHECK 1: check targets against database */
+ _alpm_log(PM_LOG_DEBUG, _("checkconflicts: target '%s' vs db"), pkgname);
+
+ for(j = _alpm_db_get_pkgcache(db); j; j = j->next) {
+ pmpkg_t *dbpkg = j->data;
+
+ if(strcmp(alpm_pkg_get_name(dbpkg), pkgname) == 0) {
+ /* skip the package we're currently processing */
continue;
}
- /* CHECK 1: check targets against database */
- _alpm_log(PM_LOG_DEBUG, _("checkconflicts: targ '%s' vs db"), tp->name);
- for(k = _alpm_db_get_pkgcache(db, INFRQ_DEPENDS); k; k = k->next) {
- pmpkg_t *dp = (pmpkg_t *)k->data;
- if(!strcmp(dp->name, tp->name)) {
- /* a package cannot conflict with itself -- that's just not nice */
- continue;
- }
- if(!strcmp(j->data, dp->name)) {
- /* conflict */
- _alpm_log(PM_LOG_DEBUG, _("targs vs db: found %s as a conflict for %s"),
- dp->name, tp->name);
- miss = _alpm_depmiss_new(tp->name, PM_DEP_TYPE_CONFLICT, PM_DEP_MOD_ANY, dp->name, NULL);
- if(!_alpm_depmiss_isin(miss, baddeps)) {
- baddeps = alpm_list_add(baddeps, miss);
- } else {
- FREE(miss);
- }
- } else {
- /* see if dp provides something in tp's conflict list */
- alpm_list_t *m;
- for(m = dp->provides; m; m = m->next) {
- if(!strcmp(m->data, j->data)) {
- /* confict */
- _alpm_log(PM_LOG_DEBUG, _("targs vs db: found %s as a conflict for %s"),
- dp->name, tp->name);
- miss = _alpm_depmiss_new(tp->name, PM_DEP_TYPE_CONFLICT, PM_DEP_MOD_ANY, dp->name, NULL);
- if(!_alpm_depmiss_isin(miss, baddeps)) {
- baddeps = alpm_list_add(baddeps, miss);
- } else {
- FREE(miss);
- }
- }
- }
- }
- }
- /* CHECK 2: check targets against targets */
- _alpm_log(PM_LOG_DEBUG, _("checkconflicts: targ '%s' vs targs"), tp->name);
- for(k = packages; k; k = k->next) {
- pmpkg_t *otp = (pmpkg_t *)k->data;
- if(!strcmp(otp->name, tp->name)) {
- /* a package cannot conflict with itself -- that's just not nice */
- continue;
- }
- if(!strcmp(otp->name, (char *)j->data)) {
- /* otp is listed in tp's conflict list */
- _alpm_log(PM_LOG_DEBUG, _("targs vs targs: found %s as a conflict for %s"),
- otp->name, tp->name);
- miss = _alpm_depmiss_new(tp->name, PM_DEP_TYPE_CONFLICT, PM_DEP_MOD_ANY, otp->name, NULL);
- if(!_alpm_depmiss_isin(miss, baddeps)) {
- baddeps = alpm_list_add(baddeps, miss);
- } else {
- FREE(miss);
- }
- } else {
- /* see if otp provides something in tp's conflict list */
- alpm_list_t *m;
- for(m = otp->provides; m; m = m->next) {
- if(!strcmp(m->data, j->data)) {
- _alpm_log(PM_LOG_DEBUG, _("targs vs targs: found %s as a conflict for %s"),
- otp->name, tp->name);
- miss = _alpm_depmiss_new(tp->name, PM_DEP_TYPE_CONFLICT, PM_DEP_MOD_ANY, otp->name, NULL);
- if(!_alpm_depmiss_isin(miss, baddeps)) {
- baddeps = alpm_list_add(baddeps, miss);
- } else {
- FREE(miss);
- }
- }
- }
- }
+
+ miss = does_conflict(pkgname, alpm_pkg_get_name(dbpkg), dbpkg, conflict);
+ if(miss && !_alpm_depmiss_isin(miss, baddeps)) {
+ baddeps = alpm_list_add(baddeps, miss);
+ } else {
+ FREE(miss);
}
}
- /* CHECK 3: check database against targets */
- _alpm_log(PM_LOG_DEBUG, _("checkconflicts: db vs targ '%s'"), tp->name);
- for(k = _alpm_db_get_pkgcache(db, INFRQ_DEPENDS); k; k = k->next) {
- alpm_list_t *conflicts = NULL;
- int usenewconflicts = 0;
-
- info = k->data;
- if(!strcmp(info->name, tp->name)) {
- /* a package cannot conflict with itself -- that's just not nice */
+ }
+ return(baddeps);
+}
+
+static alpm_list_t *chk_pkg_vs_targets(alpm_list_t *baddeps,
+ pmpkg_t *pkg, pmdb_t *db,
+ alpm_list_t *targets)
+{
+ pmdepmissing_t *miss = NULL;
+ const char *pkgname;
+ alpm_list_t *i, *j;
+
+ pkgname = alpm_pkg_get_name(pkg);
+
+ for(i = alpm_pkg_get_conflicts(pkg); i; i = i->next) {
+ const char *conflict = i->data;
+
+ if(strcmp(pkgname, conflict) == 0) {
+ /* a package cannot conflict with itself -- that's just not nice */
+ _alpm_log(PM_LOG_DEBUG, _("package '%s' conflicts with itself - packaging error"),
+ pkgname);
+ continue;
+ }
+
+ /* CHECK 2: check targets against targets */
+ _alpm_log(PM_LOG_DEBUG, _("checkconflicts: target '%s' vs all targets"), pkgname);
+
+ for(j = targets; j; j = j->next) {
+ const char *targetname;
+ pmpkg_t *target = j->data;
+ targetname = alpm_pkg_get_name(target);
+
+ if(strcmp(targetname, pkgname) == 0) {
+ /* skip the package we're currently processing */
continue;
}
- /* If this package (*info) is also in our packages alpm_list_t, use the
- * conflicts list from the new package, not the old one (*info)
- */
- for(j = packages; j; j = j->next) {
- pmpkg_t *pkg = j->data;
- if(!strcmp(pkg->name, info->name)) {
- /* Use the new, to-be-installed package's conflicts */
- conflicts = pkg->conflicts;
- usenewconflicts = 1;
- }
+
+ miss = does_conflict(pkgname, targetname, target, conflict);
+ if(miss && !_alpm_depmiss_isin(miss, baddeps)) {
+ baddeps = alpm_list_add(baddeps, miss);
+ } else {
+ FREE(miss);
}
- if(!usenewconflicts) {
- /* Use the old package's conflicts, it's the only set we have */
- conflicts = info->conflicts;
+ }
+ }
+ return(baddeps);
+}
+
+static alpm_list_t *chk_db_vs_targets(alpm_list_t *baddeps, pmpkg_t *pkg,
+ pmdb_t *db, alpm_list_t *targets)
+{
+ pmdepmissing_t *miss = NULL;
+ const char *pkgname;
+ alpm_list_t *i, *j;
+
+ pkgname = alpm_pkg_get_name(pkg);
+
+ _alpm_log(PM_LOG_DEBUG, _("checkconflicts: db vs target '%s'"), pkgname);
+
+ for(i = _alpm_db_get_pkgcache(db); i; i = i->next) {
+ alpm_list_t *conflicts = NULL;
+ const char *dbpkgname;
+
+ pmpkg_t *dbpkg = i->data;
+ dbpkgname = alpm_pkg_get_name(dbpkg);
+
+ if(strcmp(dbpkgname, pkgname) == 0) {
+ /* skip the package we're currently processing */
+ continue;
+ }
+
+ /* is this db package in the targets? if so use the
+ * new package's conflict list to pick up new changes */
+ int use_newconflicts = 0;
+ for(j = targets; j; j = j->next) {
+ pmpkg_t *targ = j->data;
+ if(strcmp(alpm_pkg_get_name(targ), dbpkgname) == 0) {
+ _alpm_log(PM_LOG_DEBUG, _("target '%s' is also in target list, using NEW conflicts"),
+ dbpkgname);
+ conflicts = alpm_pkg_get_conflicts(targ);
+ use_newconflicts = 1;
+ break;
}
- for(j = conflicts; j; j = j->next) {
- if(!strcmp((char *)j->data, tp->name)) {
- _alpm_log(PM_LOG_DEBUG, _("db vs targs: found %s as a conflict for %s"),
- info->name, tp->name);
- miss = _alpm_depmiss_new(tp->name, PM_DEP_TYPE_CONFLICT, PM_DEP_MOD_ANY, info->name, NULL);
- if(!_alpm_depmiss_isin(miss, baddeps)) {
- baddeps = alpm_list_add(baddeps, miss);
- } else {
- FREE(miss);
- }
- } else {
- /* see if the db package conflicts with something we provide */
- alpm_list_t *m;
- for(m = conflicts; m; m = m->next) {
- alpm_list_t *n;
- for(n = tp->provides; n; n = n->next) {
- if(!strcmp(m->data, n->data)) {
- _alpm_log(PM_LOG_DEBUG, _("db vs targs: found %s as a conflict for %s"),
- info->name, tp->name);
- miss = _alpm_depmiss_new(tp->name, PM_DEP_TYPE_CONFLICT, PM_DEP_MOD_ANY, info->name, NULL);
- if(!_alpm_depmiss_isin(miss, baddeps)) {
- baddeps = alpm_list_add(baddeps, miss);
- } else {
- FREE(miss);
- }
- }
- }
- }
- }
+ }
+ /* if we didn't find newer conflicts, use the original list */
+ if(!use_newconflicts) {
+ conflicts = alpm_pkg_get_conflicts(dbpkg);
+ }
+
+ for(j = conflicts; j; j = j->next) {
+ const char *conflict = j->data;
+
+
+ miss = does_conflict(pkgname, dbpkgname, pkg, conflict);
+ if(miss && !_alpm_depmiss_isin(miss, baddeps)) {
+ baddeps = alpm_list_add(baddeps, miss);
+ } else {
+ FREE(miss);
}
}
}
+ return(baddeps);
+}
+
+/* Returns a alpm_list_t* of pmdepmissing_t pointers.
+ *
+ * conflicts are always name only
+ */
+alpm_list_t *_alpm_checkconflicts(pmdb_t *db, alpm_list_t *packages)
+{
+ alpm_list_t *i, *baddeps = NULL;
+
+ ALPM_LOG_FUNC;
+
+ if(db == NULL) {
+ return(NULL);
+ }
+
+ for(i = packages; i; i = i->next) {
+ pmpkg_t *pkg = i->data;
+ if(pkg == NULL) {
+ continue;
+ }
+
+ baddeps = chk_pkg_vs_db(baddeps, pkg, db);
+ baddeps = chk_pkg_vs_targets(baddeps, pkg, db, packages);
+ baddeps = chk_db_vs_targets(baddeps, pkg, db, packages);
+ }
+
+ for(i = baddeps; i; i = i->next) {
+ pmdepmissing_t *miss = i->data;
+ _alpm_log(PM_LOG_DEBUG, _("\tCONFLICTS:: %s conflicts with %s"), miss->target, miss->depend.name);
+ }
return(baddeps);
}
+
/* Returns a alpm_list_t* of file conflicts.
* Hooray for set-intersects!
* Pre-condition: both lists are sorted!
@@ -288,8 +338,8 @@ static alpm_list_t *chk_filedifference(alpm_list_t *filesA, alpm_list_t *filesB)
* functionality that was done inline.
*/
static alpm_list_t *add_fileconflict(alpm_list_t *conflicts,
- pmconflicttype_t type, char *filestr, char* name1,
- char* name2)
+ pmconflicttype_t type, const char *filestr,
+ const char* name1, const char* name2)
{
pmconflict_t *conflict = malloc(sizeof(pmconflict_t));
if(conflict == NULL) {
@@ -349,15 +399,16 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
if(!p2) {
continue;
}
- _alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s and %s", p1->name, p2->name);
- tmpfiles = chk_fileconflicts(p1->files, p2->files);
+ _alpm_log(PM_LOG_DEBUG, "searching for file conflicts: %s and %s",
+ alpm_pkg_get_name(p1), alpm_pkg_get_name(p2));
+ tmpfiles = chk_fileconflicts(alpm_pkg_get_files(p1), alpm_pkg_get_files(p2));
if(tmpfiles) {
char path[PATH_MAX];
for(k = tmpfiles; k; k = k->next) {
snprintf(path, PATH_MAX, "%s%s", root, (char *)k->data);
- conflicts = add_fileconflict(conflicts, PM_CONFLICT_TYPE_TARGET,
- path, p1->name, p2->name);
+ conflicts = add_fileconflict(conflicts, PM_CONFLICT_TYPE_TARGET, path,
+ alpm_pkg_get_name(p1), alpm_pkg_get_name(p2));
}
alpm_list_free_inner(tmpfiles, &free);
alpm_list_free(tmpfiles);
@@ -373,10 +424,10 @@ alpm_list_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root)
* is not currently installed, then simply stat the whole filelist */
if(dbpkg) {
/* older ver of package currently installed */
- tmpfiles = chk_filedifference(p1->files, alpm_pkg_get_files(dbpkg));
+ tmpfiles = chk_filedifference(alpm_pkg_get_files(p1), alpm_pkg_get_files(dbpkg));
} else {
/* no version of package currently installed */
- tmpfiles = alpm_list_strdup(p1->files);
+ tmpfiles = alpm_list_strdup(alpm_pkg_get_files(p1));
}
/* loop over each file to be installed */
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index a44e079d..ab828614 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -71,7 +71,7 @@ pmdb_t *_alpm_db_new(const char *root, const char *dbpath, const char *treename)
FREE(db);
RET_ERR(PM_ERR_MEMORY, NULL);
}
- sprintf(db->path, "%s%s%s", root, dbpath, treename);
+ sprintf(db->path, "%s%s%s/", root, dbpath, treename);
STRNCPY(db->treename, treename, PATH_MAX);
@@ -115,23 +115,23 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles)
RET_ERR(PM_ERR_INVALID_REGEX, NULL);
}
- for(j = _alpm_db_get_pkgcache(db, INFRQ_DESC|INFRQ_DEPENDS); j; j = j->next) {
+ for(j = _alpm_db_get_pkgcache(db); j; j = j->next) {
pmpkg_t *pkg = j->data;
- char *matched = NULL;
+ const char *matched = NULL;
/* check name */
- if (regexec(&reg, pkg->name, 0, 0, 0) == 0) {
- matched = pkg->name;
+ if (regexec(&reg, alpm_pkg_get_name(pkg), 0, 0, 0) == 0) {
+ matched = alpm_pkg_get_name(pkg);
}
/* check desc */
- else if (regexec(&reg, pkg->desc, 0, 0, 0) == 0) {
- matched = pkg->desc;
+ else if (regexec(&reg, alpm_pkg_get_desc(pkg), 0, 0, 0) == 0) {
+ matched = alpm_pkg_get_desc(pkg);
}
/* check provides */
/* TODO: should we be doing this, and should we print something
* differently when we do match it since it isn't currently printed? */
else {
- for(k = pkg->provides; k; k = k->next) {
+ for(k = alpm_pkg_get_provides(pkg); k; k = k->next) {
if (regexec(&reg, k->data, 0, 0, 0) == 0) {
matched = k->data;
break;
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index 5c45432d..4ef1e591 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -58,7 +58,7 @@ int _alpm_db_install(pmdb_t *db, const char *dbfile);
int _alpm_db_open(pmdb_t *db);
void _alpm_db_close(pmdb_t *db);
void _alpm_db_rewind(pmdb_t *db);
-pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target, pmdbinfrq_t inforeq);
+pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target);
int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
int _alpm_db_remove(pmdb_t *db, pmpkg_t *info);
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 0e90c0ef..75ecab3c 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -136,8 +136,8 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
numscans++;
/* run thru targets, moving up packages as necessary */
for(i = newtargs; i; i = i->next) {
- pmpkg_t *p = (pmpkg_t*)i->data;
- _alpm_log(PM_LOG_DEBUG, "sorting %s", p->name);
+ pmpkg_t *p = i->data;
+ _alpm_log(PM_LOG_DEBUG, " sorting %s", alpm_pkg_get_name(p));
for(j = alpm_pkg_get_depends(p); j; j = j->next) {
pmdepend_t dep;
pmpkg_t *q = NULL;
@@ -148,17 +148,19 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
* move it up above p
*/
for(k = i->next; k; k = k->next) {
- q = (pmpkg_t *)k->data;
- if(!strcmp(dep.name, q->name)) {
- if(!_alpm_pkg_find(q->name, tmptargs)) {
+ q = k->data;
+ const char *qname = alpm_pkg_get_name(q);
+ if(!strcmp(dep.name, qname)) {
+ if(!_alpm_pkg_find(qname, tmptargs)) {
change = 1;
tmptargs = alpm_list_add(tmptargs, q);
}
break;
}
- for(l = q->provides; l; l = l->next) {
- if(!strcmp(dep.name, (char*)l->data)) {
- if(!_alpm_pkg_find((char*)l->data, tmptargs)) {
+ for(l = alpm_pkg_get_provides(q); l; l = l->next) {
+ const char *provname = l->data;
+ if(!strcmp(dep.name, provname)) {
+ if(!_alpm_pkg_find(provname, tmptargs)) {
change = 1;
tmptargs = alpm_list_add(tmptargs, q);
}
@@ -167,7 +169,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
}
}
}
- if(!_alpm_pkg_find(p->name, tmptargs)) {
+ if(!_alpm_pkg_find(alpm_pkg_get_name(p), tmptargs)) {
tmptargs = alpm_list_add(tmptargs, p);
}
}
@@ -221,8 +223,9 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
continue;
}
- if((oldpkg = _alpm_db_get_pkgfromcache(db, newpkg->name)) == NULL) {
- _alpm_log(PM_LOG_DEBUG, _("cannot find package installed '%s'"), newpkg->name);
+ if((oldpkg = _alpm_db_get_pkgfromcache(db, alpm_pkg_get_name(newpkg))) == NULL) {
+ _alpm_log(PM_LOG_DEBUG, _("cannot find package installed '%s'"),
+ alpm_pkg_get_name(newpkg));
continue;
}
for(j = alpm_pkg_get_requiredby(oldpkg); j; j = j->next) {
@@ -232,7 +235,7 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
/* hmmm... package isn't installed.. */
continue;
}
- if(_alpm_pkg_find(p->name, packages)) {
+ if(_alpm_pkg_find(alpm_pkg_get_name(p), packages)) {
/* this package also in the upgrade list, so don't worry about it */
continue;
}
@@ -250,7 +253,7 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
if(_alpm_depcmp(pkg, &depend)) {
_alpm_log(PM_LOG_DEBUG, _("checkdeps: dependency '%s' has moved from '%s' to '%s'"),
- depend.name, oldpkg->name, pkg->name);
+ depend.name, alpm_pkg_get_name(oldpkg), alpm_pkg_get_name(pkg));
satisfied = 1;
break;
}
@@ -259,17 +262,17 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
if(!satisfied) {
/* worst case... check installed packages to see if anything else
* satisfies this... */
- for(l = _alpm_db_get_pkgcache(db, INFRQ_DEPENDS); l; l = l->next) {
+ for(l = _alpm_db_get_pkgcache(db); l; l = l->next) {
pmpkg_t *pkg = l->data;
- if(strcmp(pkg->name, oldpkg->name) == 0) {
+ if(strcmp(alpm_pkg_get_name(pkg), alpm_pkg_get_name(oldpkg)) == 0) {
/* well, we know this one succeeds, but we're removing it... skip it */
continue;
}
if(_alpm_depcmp(pkg, &depend)) {
_alpm_log(PM_LOG_DEBUG, _("checkdeps: dependency '%s' satisfied by installed package '%s'"),
- depend.name, pkg->name);
+ depend.name, alpm_pkg_get_name(pkg));
satisfied = 1;
break;
}
@@ -278,7 +281,7 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
if(!satisfied) {
_alpm_log(PM_LOG_DEBUG, _("checkdeps: updated '%s' won't satisfy a dependency of '%s'"),
- oldpkg->name, p->name);
+ alpm_pkg_get_name(oldpkg), alpm_pkg_get_name(p));
miss = _alpm_depmiss_new(p->name, PM_DEP_TYPE_REQUIRED, depend.mod,
depend.name, depend.version);
if(!_alpm_depmiss_isin(miss, baddeps)) {
@@ -301,28 +304,19 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
continue;
}
- /* ensure package has depends data */
- pmdb_t *pkgdb = tp->data;
- _alpm_db_read(pkgdb, tp, INFRQ_DEPENDS);
- if(!tp->depends) {
- _alpm_log(PM_LOG_DEBUG, _("no dependencies for target '%s'"), tp->name);
- }
-
- for(j = tp->depends; j; j = j->next) {
+ for(j = alpm_pkg_get_depends(tp); j; j = j->next) {
/* split into name/version pairs */
_alpm_splitdep((char *)j->data, &depend);
found = 0;
/* check database for literal packages */
- for(k = _alpm_db_get_pkgcache(db, INFRQ_DESC|INFRQ_DEPENDS);
- k && !found; k = k->next) {
+ for(k = _alpm_db_get_pkgcache(db); k && !found; k = k->next) {
pmpkg_t *p = (pmpkg_t *)k->data;
found = _alpm_depcmp(p, &depend);
}
/* check database for provides matches */
if(!found) {
alpm_list_t *m;
- k = _alpm_db_whatprovides(db, depend.name);
- for(m = k; m && !found; m = m->next) {
+ for(m = _alpm_db_whatprovides(db, depend.name); m && !found; m = m->next) {
/* look for a match that isn't one of the packages we're trying
* to install. this way, if we match against a to-be-installed
* package, we'll defer to the NEW one, not the one already
@@ -332,7 +326,7 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
int skip = 0;
for(n = packages; n && !skip; n = n->next) {
pmpkg_t *ptp = n->data;
- if(!strcmp(ptp->name, p->name)) {
+ if(strcmp(alpm_pkg_get_name(ptp), alpm_pkg_get_name(p)) == 0) {
skip = 1;
}
}
@@ -346,14 +340,14 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
}
/* check other targets */
for(k = packages; k && !found; k = k->next) {
- pmpkg_t *p = (pmpkg_t *)k->data;
+ pmpkg_t *p = k->data;
found = _alpm_depcmp(p, &depend);
}
/* else if still not found... */
if(!found) {
_alpm_log(PM_LOG_DEBUG, _("missing dependency '%s' for package '%s'"),
- depend.name, tp->name);
- miss = _alpm_depmiss_new(tp->name, PM_DEP_TYPE_DEPEND, depend.mod,
+ depend.name, alpm_pkg_get_name(tp));
+ miss = _alpm_depmiss_new(alpm_pkg_get_name(tp), PM_DEP_TYPE_DEPEND, depend.mod,
depend.name, depend.version);
if(!_alpm_depmiss_isin(miss, baddeps)) {
baddeps = alpm_list_add(baddeps, miss);
@@ -372,20 +366,20 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
}
found=0;
- for(j = tp->requiredby; j; j = j->next) {
+ for(j = alpm_pkg_get_requiredby(tp); j; j = j->next) {
/* Search for 'reqname' in packages for removal */
char *reqname = j->data;
alpm_list_t *x = NULL;
for(x = packages; x; x = x->next) {
pmpkg_t *xp = x->data;
- if(strcmp(reqname, xp->name) == 0) {
+ if(strcmp(reqname, alpm_pkg_get_name(xp)) == 0) {
found = 1;
break;
}
}
if(!found) {
/* check if a package in trans->packages provides this package */
- for(k=trans->packages; !found && k; k=k->next) {
+ for(k = trans->packages; !found && k; k=k->next) {
pmpkg_t *spkg = NULL;
if(trans->type == PM_TRANS_TYPE_SYNC) {
pmsyncpkg_t *sync = k->data;
@@ -394,16 +388,16 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
spkg = k->data;
}
if(spkg) {
- if(alpm_list_find_str(spkg->provides, tp->name)) {
+ if(alpm_list_find_str(alpm_pkg_get_provides(spkg), tp->name)) {
found = 1;
}
}
}
if(!found) {
_alpm_log(PM_LOG_DEBUG, _("checkdeps: found %s as required by %s"),
- reqname, tp->name);
- miss = _alpm_depmiss_new(tp->name, PM_DEP_TYPE_REQUIRED,
- PM_DEP_MOD_ANY, j->data, NULL);
+ reqname, alpm_pkg_get_name(tp));
+ miss = _alpm_depmiss_new(alpm_pkg_get_name(tp), PM_DEP_TYPE_REQUIRED,
+ PM_DEP_MOD_ANY, j->data, NULL);
if(!_alpm_depmiss_isin(miss, baddeps)) {
baddeps = alpm_list_add(baddeps, miss);
} else {
@@ -468,20 +462,20 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets)
{
alpm_list_t *i;
- if(_alpm_pkg_find(pkg->name, targets)) {
+ if(_alpm_pkg_find(alpm_pkg_get_name(pkg), targets)) {
return(0);
}
/* see if it was explicitly installed */
if(alpm_pkg_get_reason(pkg) == PM_PKG_REASON_EXPLICIT) {
- _alpm_log(PM_LOG_DEBUG, _("excluding %s -- explicitly installed"), pkg->name);
+ _alpm_log(PM_LOG_DEBUG, _("excluding %s -- explicitly installed"), alpm_pkg_get_name(pkg));
return(0);
}
/* see if other packages need it */
for(i = alpm_pkg_get_requiredby(pkg); i; i = i->next) {
pmpkg_t *reqpkg = _alpm_db_get_pkgfromcache(db, i->data);
- if(reqpkg && !_alpm_pkg_find(reqpkg->name, targets)) {
+ if(reqpkg && !_alpm_pkg_find(alpm_pkg_get_name(reqpkg), targets)) {
return(0);
}
}
@@ -527,10 +521,9 @@ alpm_list_t *_alpm_removedeps(pmdb_t *db, alpm_list_t *targs)
for(k = provides; k; k = k->next) {
pmpkg_t *provpkg = k->data;
if(can_remove_package(db, provpkg, newtargs)) {
- pmpkg_t *pkg = _alpm_pkg_new(provpkg->name, provpkg->version);
- _alpm_db_read(db, pkg, INFRQ_ALL);
+ pmpkg_t *pkg = _alpm_pkg_new(alpm_pkg_get_name(provpkg), alpm_pkg_get_version(provpkg));
- _alpm_log(PM_LOG_DEBUG, _("adding '%s' to the targets"), pkg->name);
+ _alpm_log(PM_LOG_DEBUG, _("adding '%s' to the targets"), alpm_pkg_get_name(pkg));
/* add it to the target list */
newtargs = alpm_list_add(newtargs, pkg);
@@ -540,9 +533,8 @@ alpm_list_t *_alpm_removedeps(pmdb_t *db, alpm_list_t *targs)
FREELISTPTR(provides);
} else if(can_remove_package(db, dep, newtargs)) {
pmpkg_t *pkg = _alpm_pkg_new(dep->name, dep->version);
- _alpm_db_read(db, pkg, INFRQ_ALL);
- _alpm_log(PM_LOG_DEBUG, _("adding '%s' to the targets"), pkg->name);
+ _alpm_log(PM_LOG_DEBUG, _("adding '%s' to the targets"), alpm_pkg_get_name(pkg));
/* add it to the target list */
newtargs = alpm_list_add(newtargs, pkg);
@@ -589,10 +581,10 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
/* check if one of the packages in *list already provides this dependency */
for(j = list; j && !found; j = j->next) {
- pmpkg_t *sp = (pmpkg_t *)j->data;
- if(alpm_list_find_str(sp->provides, miss->depend.name)) {
+ pmpkg_t *sp = j->data;
+ if(alpm_list_find_str(alpm_pkg_get_provides(sp), miss->depend.name)) {
_alpm_log(PM_LOG_DEBUG, _("%s provides dependency %s -- skipping"),
- sp->name, miss->depend.name);
+ alpm_pkg_get_name(sp), miss->depend.name);
found = 1;
}
}
@@ -604,18 +596,22 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
/* check literals */
for(j = dbs_sync; !sync && j; j = j->next) {
sync = _alpm_db_get_pkgfromcache(j->data, miss->depend.name);
- _alpm_db_read(j->data, sync, INFRQ_DEPENDS);
}
+ /*TODO this autoresolves the first 'provides' package... we should fix this
+ * somehow */
/* check provides */
- for(j = dbs_sync; !sync && j; j = j->next) {
- alpm_list_t *provides;
- provides = _alpm_db_whatprovides(j->data, miss->depend.name);
- if(provides) {
- sync = provides->data;
+ if(!sync) {
+ for(j = dbs_sync; !sync && j; j = j->next) {
+ alpm_list_t *provides;
+ provides = _alpm_db_whatprovides(j->data, miss->depend.name);
+ if(provides) {
+ sync = provides->data;
+ }
+ FREELISTPTR(provides);
}
- FREELISTPTR(provides);
}
- if(sync == NULL) {
+
+ if(!sync) {
_alpm_log(PM_LOG_ERROR, _("cannot resolve dependencies for \"%s\" (\"%s\" is not in the package set)"),
miss->target, miss->depend.name);
if(data) {
@@ -631,19 +627,19 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
pm_errno = PM_ERR_UNSATISFIED_DEPS;
goto error;
}
- if(_alpm_pkg_find(sync->name, list)) {
+ if(_alpm_pkg_find(alpm_pkg_get_name(sync), list)) {
/* this dep is already in the target list */
_alpm_log(PM_LOG_DEBUG, _("dependency %s is already in the target list -- skipping"),
- sync->name);
+ alpm_pkg_get_name(sync));
continue;
}
- if(!_alpm_pkg_find(sync->name, trail)) {
+ if(!_alpm_pkg_find(alpm_pkg_get_name(sync), trail)) {
/* check pmo_ignorepkg and pmo_s_ignore to make sure we haven't pulled in
* something we're not supposed to.
*/
int usedep = 1;
- if(alpm_list_find_str(handle->ignorepkg, sync->name)) {
+ if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(sync))) {
pmpkg_t *dummypkg = _alpm_pkg_new(miss->target, NULL);
QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, dummypkg, sync, NULL, &usedep);
FREEPKG(dummypkg);
@@ -654,7 +650,7 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
goto error;
}
_alpm_log(PM_LOG_DEBUG, _("pulling dependency %s (needed by %s)"),
- sync->name, syncpkg->name);
+ alpm_pkg_get_name(sync), alpm_pkg_get_name(syncpkg));
list = alpm_list_add(list, sync);
} else {
_alpm_log(PM_LOG_ERROR, _("cannot resolve dependencies for \"%s\""), miss->target);
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index f7753d7c..f720bd7f 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -82,17 +82,17 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
}
memcpy(newpkg, pkg, sizeof(pmpkg_t));
- newpkg->license = alpm_list_strdup(pkg->license);
+ newpkg->licenses = alpm_list_strdup(alpm_pkg_get_licenses(pkg));
/*newpkg->desc_localized = alpm_list_strdup(pkg->desc_localized);*/
- newpkg->requiredby = alpm_list_strdup(pkg->requiredby);
- newpkg->conflicts = alpm_list_strdup(pkg->conflicts);
- newpkg->files = alpm_list_strdup(pkg->files);
- newpkg->backup = alpm_list_strdup(pkg->backup);
- newpkg->depends = alpm_list_strdup(pkg->depends);
- newpkg->removes = alpm_list_strdup(pkg->removes);
- newpkg->groups = alpm_list_strdup(pkg->groups);
- newpkg->provides = alpm_list_strdup(pkg->provides);
- newpkg->replaces = alpm_list_strdup(pkg->replaces);
+ newpkg->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(pkg));
+ newpkg->conflicts = alpm_list_strdup(alpm_pkg_get_conflicts(pkg));
+ newpkg->files = alpm_list_strdup(alpm_pkg_get_files(pkg));
+ newpkg->backup = alpm_list_strdup(alpm_pkg_get_backup(pkg));
+ newpkg->depends = alpm_list_strdup(alpm_pkg_get_depends(pkg));
+ newpkg->removes = alpm_list_strdup(alpm_pkg_get_removes(pkg));
+ newpkg->groups = alpm_list_strdup(alpm_pkg_get_groups(pkg));
+ newpkg->provides = alpm_list_strdup(alpm_pkg_get_provides(pkg));
+ newpkg->replaces = alpm_list_strdup(alpm_pkg_get_replaces(pkg));
/* internal */
newpkg->data = (newpkg->origin == PKG_FROM_FILE) ? strdup(pkg->data) : pkg->data;
@@ -109,7 +109,7 @@ void _alpm_pkg_free(void *data)
return;
}
- FREELIST(pkg->license);
+ FREELIST(pkg->licenses);
/*FREELIST(pkg->desc_localized);*/
FREELIST(pkg->files);
FREELIST(pkg->backup);
@@ -141,28 +141,32 @@ int alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg)
}
/* compare versions and see if we need to upgrade */
- cmp = _alpm_versioncmp(pkg->version, local_pkg->version);
+ cmp = _alpm_versioncmp(alpm_pkg_get_version(pkg), alpm_pkg_get_version(local_pkg));
if(cmp != 0 && pkg->force) {
cmp = 1;
- _alpm_log(PM_LOG_WARNING, _("%s: forcing upgrade to version %s"), local_pkg->name, pkg->version);
+ _alpm_log(PM_LOG_WARNING, _("%s: forcing upgrade to version %s"),
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
} else if(cmp < 0) {
/* local version is newer */
pmdb_t *db = pkg->data;
_alpm_log(PM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)"),
- local_pkg->name, local_pkg->version, db->treename, pkg->version);
+ alpm_pkg_get_name(local_pkg), alpm_pkg_get_version(local_pkg),
+ alpm_db_get_name(db), alpm_pkg_get_version(pkg));
cmp = 0;
} else if(cmp > 0) {
/* we have an upgrade, make sure we should actually do it */
- if(alpm_list_find_str(handle->ignorepkg, pkg->name)) {
+ if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(pkg))) {
/* package should be ignored (IgnorePkg) */
_alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (%s)"),
- local_pkg->name, local_pkg->version, pkg->version);
+ alpm_pkg_get_name(local_pkg), alpm_pkg_get_version(local_pkg),
+ alpm_pkg_get_version(pkg));
cmp = 0;
} else if(_alpm_pkg_istoonew(pkg)) {
/* package too new (UpgradeDelay) */
_alpm_log(PM_LOG_WARNING, _("%s-%s: delaying upgrade of package (%s)"),
- local_pkg->name, local_pkg->version, pkg->version);
+ alpm_pkg_get_name(local_pkg), alpm_pkg_get_version(local_pkg),
+ alpm_pkg_get_version(pkg));
cmp = 0;
}
}
@@ -174,7 +178,10 @@ int alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg)
*/
int _alpm_pkg_cmp(const void *p1, const void *p2)
{
- return(strcmp(((pmpkg_t *)p1)->name, ((pmpkg_t *)p2)->name));
+ pmpkg_t *pk1 = (pmpkg_t *)p1;
+ pmpkg_t *pk2 = (pmpkg_t *)p2;
+
+ return(strcmp(alpm_pkg_get_name(pk1), alpm_pkg_get_name(pk2)));
}
/* Parses the package description file for the current package
@@ -240,7 +247,7 @@ static int parse_descfile(const char *descfile, pmpkg_t *info)
} else if(!strcmp(key, "URL")) {
STRNCPY(info->url, ptr, sizeof(info->url));
} else if(!strcmp(key, "LICENSE")) {
- info->license = alpm_list_add(info->license, strdup(ptr));
+ info->licenses = alpm_list_add(info->licenses, strdup(ptr));
} else if(!strcmp(key, "BUILDDATE")) {
STRNCPY(info->builddate, ptr, sizeof(info->builddate));
} else if(!strcmp(key, "BUILDTYPE")) {
@@ -467,7 +474,7 @@ pmpkg_t *_alpm_pkg_find(const char *needle, alpm_list_t *haystack)
for(lp = haystack; lp; lp = lp->next) {
pmpkg_t *info = lp->data;
- if(info && strcmp(info->name, needle) == 0) {
+ if(info && strcmp(alpm_pkg_get_name(info), needle) == 0) {
return(info);
}
}
@@ -533,12 +540,12 @@ void _alpm_pkg_update_requiredby(pmpkg_t *pkg)
alpm_list_t *i, *j, *k;
pmdb_t *localdb = alpm_option_get_localdb();
- for(i = _alpm_db_get_pkgcache(localdb, INFRQ_DEPENDS); i; i = i->next) {
+ for(i = _alpm_db_get_pkgcache(localdb); i; i = i->next) {
if(!i->data) {
continue;
}
pmpkg_t *cachepkg = i->data;
- for(j = cachepkg->depends; j; j = j->next) {
+ for(j = alpm_pkg_get_depends(cachepkg); j; j = j->next) {
pmdepend_t dep;
if(!j->data) {
continue;
@@ -548,19 +555,23 @@ void _alpm_pkg_update_requiredby(pmpkg_t *pkg)
}
/* check the actual package itself */
- if(strcmp(dep.name, pkg->name) == 0) {
+ if(strcmp(dep.name, alpm_pkg_get_name(pkg)) == 0) {
_alpm_log(PM_LOG_DEBUG, _("adding '%s' in requiredby field for '%s'"),
cachepkg->name, pkg->name);
- pkg->requiredby = alpm_list_add(pkg->requiredby, strdup(cachepkg->name));
+ alpm_list_t *reqs = alpm_pkg_get_requiredby(pkg);
+ reqs = alpm_list_add(reqs, strdup(alpm_pkg_get_name(cachepkg)));
+ pkg->requiredby = reqs;
}
/* check for provisions as well */
- for(k = pkg->provides; k; k = k->next) {
+ for(k = alpm_pkg_get_provides(pkg); k; k = k->next) {
const char *provname = k->data;
if(strcmp(dep.name, provname) == 0) {
_alpm_log(PM_LOG_DEBUG, _("adding '%s' in requiredby field for '%s' (provides: %s)"),
- cachepkg->name, pkg->name, provname);
- pkg->requiredby = alpm_list_add(pkg->requiredby, strdup(cachepkg->name));
+ alpm_pkg_get_name(cachepkg), alpm_pkg_get_name(pkg), provname);
+ alpm_list_t *reqs = alpm_pkg_get_requiredby(pkg);
+ reqs = alpm_list_add(reqs, strdup(alpm_pkg_get_name(cachepkg)));
+ pkg->requiredby = reqs;
}
}
}
@@ -799,7 +810,7 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_licenses(pmpkg_t *pkg)
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
_alpm_db_read(pkg->data, pkg, INFRQ_DESC);
}
- return pkg->license;
+ return pkg->licenses;
}
alpm_list_t SYMEXPORT *alpm_pkg_get_groups(pmpkg_t *pkg)
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index f849ba85..8055c177 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -71,7 +71,7 @@ struct __pmpkg_t {
time_t date;
pmpkgreason_t reason;
/* alpm_list_t *desc_localized;*/
- alpm_list_t *license;
+ alpm_list_t *licenses;
alpm_list_t *replaces;
alpm_list_t *groups;
alpm_list_t *files;
diff --git a/lib/libalpm/provide.c b/lib/libalpm/provide.c
index a01f059a..3b563365 100644
--- a/lib/libalpm/provide.c
+++ b/lib/libalpm/provide.c
@@ -42,7 +42,7 @@ alpm_list_t *_alpm_db_whatprovides(pmdb_t *db, const char *package)
return(NULL);
}
- for(lp = _alpm_db_get_pkgcache(db, INFRQ_DEPENDS); lp; lp = lp->next) {
+ for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
pmpkg_t *info = lp->data;
if(alpm_list_find_str(alpm_pkg_get_provides(info), package)) {
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 0fd08732..68900b5f 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -73,7 +73,7 @@ int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
}
- if((info = _alpm_db_scan(db, name, INFRQ_ALL)) == NULL) {
+ if((info = _alpm_db_scan(db, name)) == NULL) {
/* Unimportant - just ignore it if we can't find it */
_alpm_log(PM_LOG_DEBUG, _("could not find %s in database"), name);
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
@@ -115,9 +115,9 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
alpm_list_t *i;
for(i = lp; i; i = i->next) {
pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
- pmpkg_t *info = _alpm_db_scan(db, miss->depend.name, INFRQ_ALL);
+ pmpkg_t *info = _alpm_db_scan(db, miss->depend.name);
if(info) {
- _alpm_log(PM_LOG_DEBUG, _("pulling %s in the targets list"), info->name);
+ _alpm_log(PM_LOG_DEBUG, _("pulling %s in the targets list"), alpm_pkg_get_name(info));
trans->packages = alpm_list_add(trans->packages, info);
} else {
_alpm_log(PM_LOG_ERROR, _("could not find %s in database -- skipping"),
@@ -200,7 +200,7 @@ static void unlink_file(pmpkg_t *info, alpm_list_t *lp, alpm_list_t *targ,
percent = (double)*position / filenum;
}
- char *hash = _alpm_needbackup(lp->data, info->backup);
+ char *hash = _alpm_needbackup(lp->data, alpm_pkg_get_backup(info));
if(hash) {
needbackup = 1;
FREE(hash);
@@ -275,6 +275,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
for(targ = trans->packages; targ; targ = targ->next) {
int position = 0;
char pm_install[PATH_MAX];
+ alpm_list_t *files;
info = (pmpkg_t*)targ->data;
if(handle->trans->state == STATE_INTERRUPTED) {
@@ -283,54 +284,63 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
- _alpm_log(PM_LOG_DEBUG, _("removing package %s-%s"), info->name, info->version);
+ _alpm_log(PM_LOG_DEBUG, _("removing package %s-%s"),
+ alpm_pkg_get_name(info), alpm_pkg_get_version(info));
/* run the pre-remove scriptlet if it exists */
- if(info->scriptlet && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version);
- _alpm_runscriptlet(handle->root, pm_install, "pre_remove", info->version, NULL, trans);
+ if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
+ snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db->path,
+ alpm_pkg_get_name(info), alpm_pkg_get_version(info));
+ _alpm_runscriptlet(handle->root, pm_install, "pre_remove",
+ alpm_pkg_get_version(info), NULL, trans);
}
}
+ files = alpm_pkg_get_files(info);
+
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
- for(lp = info->files; lp; lp = lp->next) {
+ for(lp = files; lp; lp = lp->next) {
if(!can_remove_file(trans, lp->data)) {
- _alpm_log(PM_LOG_DEBUG, _("not removing package '%s', can't remove all files"), info->name);
+ _alpm_log(PM_LOG_DEBUG, _("not removing package '%s', can't remove all files"),
+ alpm_pkg_get_name(info));
RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
}
}
- int filenum = alpm_list_count(info->files);
- _alpm_log(PM_LOG_DEBUG, _("removing files"));
+ int filenum = alpm_list_count(files);
+ _alpm_log(PM_LOG_DEBUG, _("removing %d files"), filenum);
/* iterate through the list backwards, unlinking files */
- for(lp = alpm_list_last(info->files); lp; lp = lp->prev) {
+ for(lp = alpm_list_last(files); lp; lp = lp->prev) {
unlink_file(info, lp, targ, trans, filenum, &position);
}
}
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
/* run the post-remove script if it exists */
- if(info->scriptlet && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version);
- _alpm_runscriptlet(handle->root, pm_install, "post_remove", info->version, NULL, trans);
+ if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
+ snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db->path,
+ alpm_pkg_get_name(info), alpm_pkg_get_version(info));
+ _alpm_runscriptlet(handle->root, pm_install, "post_remove",
+ alpm_pkg_get_version(info), NULL, trans);
}
}
/* remove the package from the database */
_alpm_log(PM_LOG_DEBUG, _("updating database"));
- _alpm_log(PM_LOG_DEBUG, _("removing database entry '%s'"), info->name);
+ _alpm_log(PM_LOG_DEBUG, _("removing database entry '%s'"), alpm_pkg_get_name(info));
if(_alpm_db_remove(db, info) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s"), info->name, info->version);
+ _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s"),
+ alpm_pkg_get_name(info), alpm_pkg_get_version(info));
}
if(_alpm_db_remove_pkgfromcache(db, info) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache"), info->name);
+ _alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache"), alpm_pkg_get_name(info));
}
/* update dependency packages' REQUIREDBY fields */
_alpm_trans_update_depends(trans, info);
- PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, info->name, 100, alpm_list_count(trans->packages), (alpm_list_count(trans->packages) - alpm_list_count(targ) +1));
+ PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, alpm_pkg_get_name(info), 100, alpm_list_count(trans->packages), (alpm_list_count(trans->packages) - alpm_list_count(targ) +1));
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
EVENT(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL);
}
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 81d2a738..6f5a715d 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -91,37 +91,13 @@ void _alpm_sync_free(void *data)
FREE(sync);
}
-/* Test for existence of a package in a alpm_list_t* of pmsyncpkg_t*
- * If found, return a pointer to the respective pmsyncpkg_t*
- */
-static pmsyncpkg_t *find_pkginsync(char *needle, alpm_list_t *haystack)
-{
- alpm_list_t *i;
- pmsyncpkg_t *sync = NULL;
- int found = 0;
-
- ALPM_LOG_FUNC;
-
- for(i = haystack; i && !found; i = i->next) {
- sync = i->data;
- if(sync && !strcmp(sync->pkg->name, needle)) {
- found = 1;
- }
- }
- if(!found) {
- sync = NULL;
- }
-
- return(sync);
-}
-
/* Find recommended replacements for packages during a sync.
* (refactored from _alpm_sync_prepare)
*/
static int find_replacements(pmtrans_t *trans, pmdb_t *db_local,
alpm_list_t *dbs_sync)
{
- alpm_list_t *i, *j, *k, *m; /* wow */
+ alpm_list_t *i, *j, *k; /* wow */
ALPM_LOG_FUNC;
@@ -131,57 +107,57 @@ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local,
pmdb_t *db = i->data;
/* for each db, check each package's REPLACES list */
- for(j = _alpm_db_get_pkgcache(db, INFRQ_DESC); j; j = j->next) {
+ for(j = _alpm_db_get_pkgcache(db); j; j = j->next) {
pmpkg_t *spkg = j->data;
for(k = alpm_pkg_get_replaces(spkg); k; k = k->next) {
const char *replacement = k->data;
- /* compare to local DB */
- for(m = _alpm_db_get_pkgcache(db_local, INFRQ_BASE); m; m = m->next) {
- pmpkg_t *lpkg = m->data;
-
- if(strcmp(replacement, lpkg->name) == 0) {
- _alpm_log(PM_LOG_DEBUG, _("checking replacement '%s' for package '%s'"), replacement, spkg->name);
- if(alpm_list_find_str(handle->ignorepkg, lpkg->name)) {
- _alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (to be replaced by %s-%s)"),
- lpkg->name, lpkg->version, spkg->name, spkg->version);
+
+ pmpkg_t *lpkg = _alpm_db_get_pkgfromcache(db_local, replacement);
+ if(!lpkg) {
+ continue;
+ }
+
+ _alpm_log(PM_LOG_DEBUG, _("checking replacement '%s' for package '%s'"), replacement, spkg->name);
+ if(alpm_list_find_str(handle->ignorepkg, lpkg->name)) {
+ _alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (to be replaced by %s-%s)"),
+ alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg),
+ alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
+ } else {
+ /* get confirmation for the replacement */
+ int doreplace = 0;
+ QUESTION(trans, PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, db->treename, &doreplace);
+
+ if(doreplace) {
+ /* if confirmed, add this to the 'final' list, designating 'lpkg' as
+ * the package to replace.
+ */
+ pmsyncpkg_t *sync;
+ pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(lpkg), NULL);
+ if(dummy == NULL) {
+ pm_errno = PM_ERR_MEMORY;
+ goto error;
+ }
+ dummy->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(lpkg));
+ /* check if spkg->name is already in the packages list. */
+ sync = _alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg));
+ if(sync) {
+ /* found it -- just append to the replaces list */
+ sync->data = alpm_list_add(sync->data, dummy);
} else {
- /* get confirmation for the replacement */
- int doreplace = 0;
- QUESTION(trans, PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, db->treename, &doreplace);
-
- if(doreplace) {
- /* if confirmed, add this to the 'final' list, designating 'lpkg' as
- * the package to replace.
- */
- pmsyncpkg_t *sync;
- pmpkg_t *dummy = _alpm_pkg_new(lpkg->name, NULL);
- if(dummy == NULL) {
- pm_errno = PM_ERR_MEMORY;
- goto error;
- }
- dummy->requiredby = alpm_list_strdup(lpkg->requiredby);
- /* check if spkg->name is already in the packages list. */
- sync = find_pkginsync(spkg->name, trans->packages);
- if(sync) {
- /* found it -- just append to the replaces list */
- sync->data = alpm_list_add(sync->data, dummy);
- } else {
- /* none found -- enter pkg into the final sync list */
- sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL);
- if(sync == NULL) {
- FREEPKG(dummy);
- pm_errno = PM_ERR_MEMORY;
- goto error;
- }
- sync->data = alpm_list_add(NULL, dummy);
- trans->packages = alpm_list_add(trans->packages, sync);
- }
- _alpm_log(PM_LOG_DEBUG, _("%s-%s elected for upgrade (to be replaced by %s-%s)"),
- lpkg->name, lpkg->version, spkg->name, spkg->version);
+ /* none found -- enter pkg into the final sync list */
+ sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL);
+ if(sync == NULL) {
+ FREEPKG(dummy);
+ pm_errno = PM_ERR_MEMORY;
+ goto error;
}
+ sync->data = alpm_list_add(NULL, dummy);
+ trans->packages = alpm_list_add(trans->packages, sync);
}
- break;
+ _alpm_log(PM_LOG_DEBUG, _("%s-%s elected for upgrade (to be replaced by %s-%s)"),
+ alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg),
+ alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
}
}
}
@@ -200,20 +176,20 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
ALPM_LOG_FUNC;
/* check for "recommended" package replacements */
- if( find_replacements(trans, db_local, dbs_sync) == 0 ) {
+ if(find_replacements(trans, db_local, dbs_sync) == 0) {
/* match installed packages with the sync dbs and compare versions */
_alpm_log(PM_LOG_DEBUG, _("checking for package upgrades"));
- for(i = _alpm_db_get_pkgcache(db_local, INFRQ_BASE); i; i = i->next) {
+ for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) {
int replace=0;
pmpkg_t *local = i->data;
pmpkg_t *spkg = NULL;
pmsyncpkg_t *sync;
for(j = dbs_sync; !spkg && j; j = j->next) {
- spkg = _alpm_db_get_pkgfromcache(j->data, local->name);
+ spkg = _alpm_db_get_pkgfromcache(j->data, alpm_pkg_get_name(local));
}
if(spkg == NULL) {
- _alpm_log(PM_LOG_DEBUG, _("'%s' not found in sync db -- skipping"), local->name);
+ _alpm_log(PM_LOG_DEBUG, _("'%s' not found in sync db -- skipping"), alpm_pkg_get_name(local));
continue;
}
@@ -221,23 +197,25 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
for(j = trans->packages; j && !replace; j=j->next) {
sync = j->data;
if(sync->type == PM_SYNC_TYPE_REPLACE) {
- if(_alpm_pkg_find(spkg->name, sync->data)) {
+ if(_alpm_pkg_find(alpm_pkg_get_name(spkg), sync->data)) {
replace=1;
}
}
}
if(replace) {
_alpm_log(PM_LOG_DEBUG, _("'%s' is already elected for removal -- skipping"),
- local->name);
+ alpm_pkg_get_name(local));
continue;
}
/* compare versions and see if we need to upgrade */
if(alpm_pkg_compare_versions(local, spkg)) {
_alpm_log(PM_LOG_DEBUG, _("%s-%s elected for upgrade (%s => %s)"),
- local->name, local->version, local->version, spkg->version);
- if(!find_pkginsync(spkg->name, trans->packages)) {
- pmpkg_t *dummy = _alpm_pkg_new(local->name, local->version);
+ alpm_pkg_get_name(local), alpm_pkg_get_version(local),
+ alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
+ if(!_alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg))) {
+ pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(local),
+ alpm_pkg_get_version(local));
if(dummy == NULL) {
goto error;
}
@@ -279,22 +257,21 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
if(targ) {
*targ = '\0';
targ++;
- _alpm_log(PM_LOG_DEBUG, _("searching for target in repo '%s'"), targline);
+ _alpm_log(PM_LOG_DEBUG, _("searching for target in repo '%s'"), targ);
for(j = dbs_sync; j && !spkg; j = j->next) {
- pmdb_t *dbs = j->data;
- if(strcmp(dbs->treename, targline) == 0) {
+ pmdb_t *db = j->data;
+ if(strcmp(db->treename, targline) == 0) {
repo_found = 1;
- spkg = _alpm_db_get_pkgfromcache(dbs, targ);
+ spkg = _alpm_db_get_pkgfromcache(db, targ);
if(spkg == NULL) {
/* Search provides */
- alpm_list_t *p;
_alpm_log(PM_LOG_DEBUG, _("target '%s' not found -- looking for provisions"), targ);
- p = _alpm_db_whatprovides(dbs, targ);
- if(p == NULL) {
+ alpm_list_t *p = _alpm_db_whatprovides(db, targ);
+ if(!p) {
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
}
_alpm_log(PM_LOG_DEBUG, _("found '%s' as a provision for '%s'"), p->data, targ);
- spkg = _alpm_db_get_pkgfromcache(dbs, p->data);
+ spkg = _alpm_db_get_pkgfromcache(db, p->data);
FREELISTPTR(p);
}
}
@@ -306,33 +283,34 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
} else {
targ = targline;
for(j = dbs_sync; j && !spkg; j = j->next) {
- pmdb_t *dbs = j->data;
- spkg = _alpm_db_get_pkgfromcache(dbs, targ);
+ pmdb_t *db = j->data;
+ spkg = _alpm_db_get_pkgfromcache(db, targ);
}
if(spkg == NULL) {
/* Search provides */
_alpm_log(PM_LOG_DEBUG, _("target '%s' not found -- looking for provisions"), targ);
for(j = dbs_sync; j && !spkg; j = j->next) {
- pmdb_t *dbs = j->data;
- alpm_list_t *p = _alpm_db_whatprovides(dbs, targ);
+ pmdb_t *db = j->data;
+ alpm_list_t *p = _alpm_db_whatprovides(db, targ);
if(p) {
_alpm_log(PM_LOG_DEBUG, _("found '%s' as a provision for '%s'"), p->data, targ);
- spkg = _alpm_db_get_pkgfromcache(dbs, p->data);
+ spkg = _alpm_db_get_pkgfromcache(db, p->data);
FREELISTPTR(p);
}
}
}
}
+
if(spkg == NULL) {
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
}
- local = _alpm_db_get_pkgfromcache(db_local, spkg->name);
+ local = _alpm_db_get_pkgfromcache(db_local, alpm_pkg_get_name(spkg));
if(local) {
if(alpm_pkg_compare_versions(local, spkg) == 0) {
/* spkg is NOT an upgrade, get confirmation before adding */
int resp = 0;
- if(alpm_list_find_str(handle->ignorepkg, local->name)) {
+ if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(local))) {
QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, local, NULL, NULL, &resp);
if(!resp) {
return(0);
@@ -340,7 +318,8 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
} else {
QUESTION(trans, PM_TRANS_CONV_LOCAL_UPTODATE, local, NULL, NULL, &resp);
if(!resp) {
- _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- skipping"), local->name, local->version);
+ _alpm_log(PM_LOG_WARNING, _("%s-%s is up to date -- skipping"),
+ alpm_pkg_get_name(local), alpm_pkg_get_version(local));
return(0);
}
}
@@ -348,10 +327,11 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
}
/* add the package to the transaction */
- if(!find_pkginsync(spkg->name, trans->packages)) {
+ if(!_alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg))) {
pmpkg_t *dummy = NULL;
if(local) {
- dummy = _alpm_pkg_new(local->name, local->version);
+ dummy = _alpm_pkg_new(alpm_pkg_get_name(local),
+ alpm_pkg_get_version(local));
if(dummy == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
@@ -361,7 +341,8 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
FREEPKG(dummy);
RET_ERR(PM_ERR_MEMORY, -1);
}
- _alpm_log(PM_LOG_DEBUG, _("adding target '%s' to the transaction set"), spkg->name);
+ _alpm_log(PM_LOG_DEBUG, _("adding target '%s' to the transaction set"),
+ alpm_pkg_get_name(spkg));
trans->packages = alpm_list_add(trans->packages, sync);
}
@@ -372,12 +353,14 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
*/
static int syncpkg_cmp(const void *s1, const void *s2)
{
- return(strcmp(((pmsyncpkg_t *)s1)->pkg->name, ((pmsyncpkg_t *)s2)->pkg->name));
-}
+ pmsyncpkg_t *sp1 = (pmsyncpkg_t *)s1;
+ pmsyncpkg_t *sp2 = (pmsyncpkg_t *)s2;
+ pmpkg_t *p1, *p2;
-static int pkg_cmp(const void *p1, const void *p2)
-{
- return(strcmp(((pmpkg_t *)p1)->name, ((pmsyncpkg_t *)p2)->pkg->name));
+ p1 = alpm_sync_get_pkg(sp1);
+ p2 = alpm_sync_get_pkg(sp2);
+
+ return(strcmp(alpm_pkg_get_name(p1), alpm_pkg_get_name(p2)));
}
int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data)
@@ -419,7 +402,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
for(i = list; i; i = i->next) {
/* add the dependencies found by resolvedeps to the transaction set */
pmpkg_t *spkg = i->data;
- if(!find_pkginsync(spkg->name, trans->packages)) {
+ if(!_alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg))) {
pmsyncpkg_t *sync = _alpm_sync_new(PM_SYNC_TYPE_DEPEND, spkg, NULL);
if(sync == NULL) {
ret = -1;
@@ -427,13 +410,13 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
}
trans->packages = alpm_list_add(trans->packages, sync);
_alpm_log(PM_LOG_DEBUG, _("adding package %s-%s to the transaction targets"),
- spkg->name, spkg->version);
+ alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
} else {
/* remove the original targets from the list if requested */
if((trans->flags & PM_TRANS_FLAG_DEPENDSONLY)) {
void *vp;
pmpkg_t *p;
- trans->packages = alpm_list_remove(trans->packages, spkg, pkg_cmp, &vp);
+ trans->packages = alpm_list_remove(trans->packages, spkg, _alpm_pkg_cmp, &vp);
p = vp;
FREEPKG(p);
}
@@ -492,7 +475,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
pmsyncpkg_t *sync;
pmpkg_t *local;
- _alpm_log(PM_LOG_DEBUG, _("package '%s' is conflicting with '%s'"),
+ _alpm_log(PM_LOG_DEBUG, _("package '%s' conflicts with '%s'"),
miss->target, miss->depend.name);
/* check if the conflicting package is one that's about to be removed/replaced.
@@ -512,7 +495,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
continue;
}
- sync = find_pkginsync(miss->target, trans->packages);
+ sync = _alpm_sync_find(trans->packages, miss->target);
if(sync == NULL) {
_alpm_log(PM_LOG_DEBUG, _("'%s' not found in transaction set -- skipping"),
miss->target);
@@ -521,7 +504,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
local = _alpm_db_get_pkgfromcache(db_local, miss->depend.name);
/* check if this package also "provides" the package it's conflicting with
*/
- if(alpm_list_find_str(sync->pkg->provides, miss->depend.name)) {
+ if(alpm_list_find_str(alpm_pkg_get_provides(sync->pkg), miss->depend.name)) {
/* so just treat it like a "replaces" item so the REQUIREDBY
* fields are inherited properly.
*/
@@ -563,7 +546,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
rmpkg = miss->depend.name;
}
if(rmpkg) {
- pmsyncpkg_t *rsync = find_pkginsync(rmpkg, trans->packages);
+ pmsyncpkg_t *rsync = _alpm_sync_find(trans->packages, rmpkg);
void *vpkg;
_alpm_log(PM_LOG_DEBUG, _("removing '%s' from target list"), rsync->pkg->name);
trans->packages = alpm_list_remove(trans->packages, rsync, syncpkg_cmp, &vpkg);
@@ -581,7 +564,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
QUESTION(trans, PM_TRANS_CONV_CONFLICT_PKG, miss->target, miss->depend.name, NULL, &doremove);
asked = alpm_list_add(asked, strdup(miss->depend.name));
if(doremove) {
- pmsyncpkg_t *rsync = find_pkginsync(miss->depend.name, trans->packages);
+ pmsyncpkg_t *rsync = _alpm_sync_find(trans->packages, miss->depend.name);
pmpkg_t *q = _alpm_pkg_new(miss->depend.name, NULL);
if(q == NULL) {
if(data) {
@@ -590,7 +573,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
ret = -1;
goto cleanup;
}
- q->requiredby = alpm_list_strdup(local->requiredby);
+ q->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(local));
if(sync->type != PM_SYNC_TYPE_REPLACE) {
/* switch this sync type to REPLACE */
sync->type = PM_SYNC_TYPE_REPLACE;
@@ -682,7 +665,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
int errorout = 0;
for(i = deps; i; i = i->next) {
pmdepmissing_t *miss = i->data;
- if(!find_pkginsync(miss->depend.name, trans->packages)) {
+ if(!_alpm_sync_find(trans->packages, miss->depend.name)) {
int pfound = 0;
alpm_list_t *k;
/* If miss->depend.name depends on something that miss->target and a
@@ -696,9 +679,9 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
}
/* Look through the upset package's dependencies and try to match one up
* to a provisio from the package we want to remove */
- for(k = conflictp->depends; k && !pfound; k = k->next) {
+ for(k = alpm_pkg_get_depends(conflictp); k && !pfound; k = k->next) {
alpm_list_t *m;
- for(m = leavingp->provides; m && !pfound; m = m->next) {
+ for(m = alpm_pkg_get_provides(leavingp); m && !pfound; m = m->next) {
if(!strcmp(k->data, m->data)) {
/* Found a match -- now look through final for a package that
* provides the same thing. If none are found, then it truly
@@ -706,11 +689,12 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
alpm_list_t *n, *o;
for(n = trans->packages; n && !pfound; n = n->next) {
pmsyncpkg_t *sp = n->data;
- for(o = sp->pkg->provides; o && !pfound; o = o->next) {
+ pmpkg_t *sppkg = sp->pkg;
+ for(o = alpm_pkg_get_provides(sppkg); o && !pfound; o = o->next) {
if(!strcmp(m->data, o->data)) {
/* found matching provisio -- we're good to go */
_alpm_log(PM_LOG_DEBUG, _("found '%s' as a provision for '%s' -- conflict aborted"),
- sp->pkg->name, (char *)o->data);
+ alpm_pkg_get_name(sppkg), (char *)o->data);
pfound = 1;
}
}
@@ -1002,13 +986,13 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
pmsyncpkg_t *sync = i->data;
if(sync->type == PM_SYNC_TYPE_REPLACE) {
alpm_list_t *j;
- pmpkg_t *new = _alpm_db_get_pkgfromcache(db_local, sync->pkg->name);
+ pmpkg_t *new = _alpm_db_get_pkgfromcache(db_local, alpm_pkg_get_name(sync->pkg));
for(j = sync->data; j; j = j->next) {
alpm_list_t *k;
pmpkg_t *old = j->data;
/* merge lists */
- for(k = old->requiredby; k; k = k->next) {
- if(!alpm_list_find_str(new->requiredby, k->data)) {
+ for(k = alpm_pkg_get_requiredby(old); k; k = k->next) {
+ if(!alpm_list_find_str(alpm_pkg_get_requiredby(new), k->data)) {
/* replace old's name with new's name in the requiredby's dependency list */
alpm_list_t *m;
pmpkg_t *depender = _alpm_db_get_pkgfromcache(db_local, k->data);
@@ -1019,24 +1003,24 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
* here. */
continue;
}
- for(m = depender->depends; m; m = m->next) {
- if(!strcmp(m->data, old->name)) {
+ for(m = alpm_pkg_get_depends(depender); m; m = m->next) {
+ if(!strcmp(m->data, alpm_pkg_get_name(old))) {
FREE(m->data);
- m->data = strdup(new->name);
+ m->data = strdup(alpm_pkg_get_name(new));
}
}
if(_alpm_db_write(db_local, depender, INFRQ_DEPENDS) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not update requiredby for database entry %s-%s"),
- new->name, new->version);
+ alpm_pkg_get_name(new), alpm_pkg_get_version(new));
}
/* add the new requiredby */
- new->requiredby = alpm_list_add(new->requiredby, strdup(k->data));
+ new->requiredby = alpm_list_add(alpm_pkg_get_requiredby(new), strdup(k->data));
}
}
}
if(_alpm_db_write(db_local, new, INFRQ_DEPENDS) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not update new database entry %s-%s"),
- new->name, new->version);
+ alpm_pkg_get_name(new), alpm_pkg_get_version(new));
}
}
}
@@ -1064,6 +1048,27 @@ error:
return(-1);
}
+pmsyncpkg_t *_alpm_sync_find(alpm_list_t *syncpkgs, const char* pkgname)
+{
+ alpm_list_t *i;
+ for(i = syncpkgs; i; i = i->next) {
+ pmsyncpkg_t *syncpkg = i->data;
+ if(!syncpkg) {
+ continue;
+ }
+
+ pmpkg_t *pkg = alpm_sync_get_pkg(syncpkg);
+ if(strcmp(alpm_pkg_get_name(pkg), pkgname) == 0) {
+ _alpm_log(PM_LOG_DEBUG, _("found package '%s-%s' in sync"),
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
+ return(syncpkg);
+ }
+ }
+
+ _alpm_log(PM_LOG_DEBUG, _("package '%s not found in sync"), pkgname);
+ return(NULL); /* not found */
+}
+
pmsynctype_t SYMEXPORT alpm_sync_get_type(pmsyncpkg_t *sync)
{
/* Sanity checks */
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h
index a2e2e11e..3ba7e009 100644
--- a/lib/libalpm/sync.h
+++ b/lib/libalpm/sync.h
@@ -42,6 +42,9 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data);
int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data);
+/* typically trans->packages */
+pmsyncpkg_t *_alpm_sync_find(alpm_list_t *syncpkgs, const char* pkgname);
+
#endif /* _ALPM_SYNC_H */
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index dc767f8b..9a301b63 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -250,6 +250,7 @@ int _alpm_trans_commit(pmtrans_t *trans, alpm_list_t **data)
int _alpm_trans_update_depends(pmtrans_t *trans, pmpkg_t *pkg)
{
alpm_list_t *i, *j;
+ alpm_list_t *depends = NULL;
pmdb_t *localdb;
ALPM_LOG_FUNC;
@@ -258,7 +259,8 @@ int _alpm_trans_update_depends(pmtrans_t *trans, pmpkg_t *pkg)
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(pkg != NULL, RET_ERR(PM_ERR_PKG_INVALID, -1));
- if(pkg->depends) {
+ depends = alpm_pkg_get_depends(pkg);
+ if(depends) {
_alpm_log(PM_LOG_DEBUG, _("updating dependency packages 'requiredby' fields for %s-%s"),
pkg->name, pkg->version);
} else {
@@ -266,7 +268,7 @@ int _alpm_trans_update_depends(pmtrans_t *trans, pmpkg_t *pkg)
}
localdb = alpm_option_get_localdb();
- for(i = pkg->depends; i; i = i->next) {
+ for(i = depends; i; i = i->next) {
pmdepend_t dep;
if(_alpm_splitdep(i->data, &dep) != 0) {
continue;
@@ -288,7 +290,7 @@ int _alpm_trans_update_depends(pmtrans_t *trans, pmpkg_t *pkg)
continue;
}
pmpkg_t *provpkg = j->data;
- deppkg = _alpm_db_get_pkgfromcache(localdb, provpkg->name);
+ deppkg = _alpm_db_get_pkgfromcache(localdb, alpm_pkg_get_name(provpkg));
if(!deppkg) {
continue;
@@ -296,20 +298,22 @@ int _alpm_trans_update_depends(pmtrans_t *trans, pmpkg_t *pkg)
found_provides = 1;
- /* Ensure package has the right newpkg */
- _alpm_db_read(localdb, deppkg, INFRQ_DEPENDS);
+ /* this is cheating... we call this function to populate the package */
+ alpm_pkg_get_requiredby(deppkg);
- _alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), deppkg->name);
+ _alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), alpm_pkg_get_name(deppkg));
if(trans->type == PM_TRANS_TYPE_REMOVE) {
void *data = NULL;
- deppkg->requiredby = alpm_list_remove(deppkg->requiredby, pkg->name, _alpm_str_cmp, &data);
+ deppkg->requiredby = alpm_list_remove(deppkg->requiredby,
+ alpm_pkg_get_name(pkg), _alpm_str_cmp, &data);
FREE(data);
} else {
- deppkg->requiredby = alpm_list_add(deppkg->requiredby, strdup(pkg->name));
+ deppkg->requiredby = alpm_list_add(deppkg->requiredby, strdup(alpm_pkg_get_name(pkg)));
}
if(_alpm_db_write(localdb, deppkg, INFRQ_DEPENDS)) {
- _alpm_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"), deppkg->name, deppkg->version);
+ _alpm_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"),
+ alpm_pkg_get_name(deppkg), alpm_pkg_get_version(deppkg));
}
}
FREELISTPTR(provides);
@@ -320,20 +324,22 @@ int _alpm_trans_update_depends(pmtrans_t *trans, pmpkg_t *pkg)
}
}
- /* Ensure package has the right newpkg */
- _alpm_db_read(localdb, deppkg, INFRQ_DEPENDS);
+ /* this is cheating... we call this function to populate the package */
+ alpm_pkg_get_requiredby(deppkg);
_alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), deppkg->name);
if(trans->type == PM_TRANS_TYPE_REMOVE) {
void *data = NULL;
- deppkg->requiredby = alpm_list_remove(deppkg->requiredby, pkg->name, _alpm_str_cmp, &data);
+ deppkg->requiredby = alpm_list_remove(deppkg->requiredby,
+ alpm_pkg_get_name(pkg), _alpm_str_cmp, &data);
FREE(data);
} else {
- deppkg->requiredby = alpm_list_add(deppkg->requiredby, strdup(pkg->name));
+ deppkg->requiredby = alpm_list_add(deppkg->requiredby, strdup(alpm_pkg_get_name(pkg)));
}
if(_alpm_db_write(localdb, deppkg, INFRQ_DEPENDS)) {
- _alpm_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"), deppkg->name, deppkg->version);
+ _alpm_log(PM_LOG_ERROR, _("could not update 'requiredby' database entry %s-%s"),
+ alpm_pkg_get_name(deppkg), alpm_pkg_get_version(deppkg));
}
}
return(0);
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 359b8bfc..dd1ba812 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -92,7 +92,7 @@ char* strsep(char** str, const char* delims)
/* Backported from Solaris Express 4/06
* Copyright (c) 2006 Sun Microsystems, Inc. */
-char * mkdtemp(char *template)
+char *mkdtemp(char *template)
{
char *t = alloca(strlen(template) + 1);
char *r;
@@ -119,7 +119,7 @@ char * mkdtemp(char *template)
#endif
/* does the same thing as 'mkdir -p' */
-int _alpm_makepath(char *path)
+int _alpm_makepath(const char *path)
{
char *orig, *str, *ptr;
char full[PATH_MAX] = "";
@@ -149,7 +149,7 @@ int _alpm_makepath(char *path)
return(0);
}
-int _alpm_copyfile(char *src, char *dest)
+int _alpm_copyfile(const char *src, const char *dest)
{
FILE *in, *out;
size_t len;
@@ -184,7 +184,7 @@ char *_alpm_strtoupper(char *str)
(*ptr) = toupper(*ptr);
ptr++;
}
- return str;
+ return(str);
}
/* Trim whitespace and newlines from a string
@@ -221,7 +221,7 @@ char *_alpm_strtrim(char *str)
/* Create a lock file
*/
-int _alpm_lckmk(char *file)
+int _alpm_lckmk(const char *file)
{
int fd, count = 0;
char *dir, *ptr;
@@ -249,7 +249,7 @@ int _alpm_lckmk(char *file)
/* Remove a lock file
*/
-int _alpm_lckrm(char *file)
+int _alpm_lckrm(const char *file)
{
if(unlink(file) == -1 && errno != ENOENT) {
return(-1);
@@ -302,7 +302,7 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
}
/* does the same thing as 'rm -rf' */
-int _alpm_rmrf(char *path)
+int _alpm_rmrf(const char *path)
{
int errflag = 0;
struct dirent *dp;
@@ -370,15 +370,15 @@ int _alpm_logaction(unsigned short usesyslog, FILE *f, const char *str)
return(0);
}
-int _alpm_ldconfig(char *root)
+int _alpm_ldconfig(const char *root)
{
char line[PATH_MAX];
struct stat buf;
snprintf(line, PATH_MAX, "%setc/ld.so.conf", root);
- if(!stat(line, &buf)) {
+ if(stat(line, &buf) == 0) {
snprintf(line, PATH_MAX, "%ssbin/ldconfig", root);
- if(!stat(line, &buf)) {
+ if(stat(line, &buf) == 0) {
char cmd[PATH_MAX];
snprintf(cmd, PATH_MAX, "%s -r %s", line, root);
system(cmd);
@@ -413,7 +413,9 @@ static int grep(const char *fn, const char *needle)
return(0);
}
-int _alpm_runscriptlet(char *root, char *installfn, char *script, char *ver, char *oldver, pmtrans_t *trans)
+int _alpm_runscriptlet(const char *root, const char *installfn,
+ const char *script, const char *ver,
+ const char *oldver, pmtrans_t *trans)
{
char scriptfn[PATH_MAX];
char cmdline[PATH_MAX];
@@ -589,13 +591,13 @@ int _alpm_check_freespace(pmtrans_t *trans, alpm_list_t **data)
pmsyncpkg_t *sync = i->data;
if(sync->type != PM_SYNC_TYPE_REPLACE) {
pmpkg_t *pkg = sync->pkg;
- pkgsize += pkg->isize;
+ pkgsize += alpm_pkg_get_isize(pkg);
}
}
else
{
pmpkg_t *pkg = i->data;
- pkgsize += pkg->size;
+ pkgsize += alpm_pkg_get_size(pkg);
}
}
freespace = get_freespace();
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 277ddb47..9f028e8a 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -55,18 +55,20 @@
#define SCRIPTLET_START "START "
#define SCRIPTLET_DONE "DONE "
-int _alpm_makepath(char *path);
-int _alpm_copyfile(char *src, char *dest);
+int _alpm_makepath(const char *path);
+int _alpm_copyfile(const char *src, const char *dest);
char *_alpm_strtoupper(char *str);
char *_alpm_strtrim(char *str);
-int _alpm_lckmk(char *file);
-int _alpm_lckrm(char *file);
+int _alpm_lckmk(const char *file);
+int _alpm_lckrm(const char *file);
int _alpm_unpack(const char *archive, const char *prefix, const char *fn);
-int _alpm_rmrf(char *path);
+int _alpm_rmrf(const char *path);
int _alpm_logaction(unsigned short usesyslog, FILE *f, const char *str);
-int _alpm_ldconfig(char *root);
+int _alpm_ldconfig(const char *root);
#ifdef _ALPM_TRANS_H
-int _alpm_runscriptlet(char *util, char *installfn, char *script, char *ver, char *oldver, pmtrans_t *trans);
+int _alpm_runscriptlet(const char *root, const char *installfn,
+ const char *script, const char *ver,
+ const char *oldver, pmtrans_t *trans);
#ifndef __sun__
int _alpm_check_freespace(pmtrans_t *trans, alpm_list_t **data);
#endif
diff --git a/lib/libalpm/versioncmp.c b/lib/libalpm/versioncmp.c
index 3356e99f..ad628866 100644
--- a/lib/libalpm/versioncmp.c
+++ b/lib/libalpm/versioncmp.c
@@ -256,7 +256,7 @@ int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
if(dep->mod == PM_DEP_MOD_ANY) {
equal = 1;
} else {
- int cmp = _alpm_versioncmp(pkg->version, dep->version);
+ int cmp = _alpm_versioncmp(alpm_pkg_get_version(pkg), dep->version);
switch(dep->mod) {
case PM_DEP_MOD_EQ: equal = (cmp == 0); break;
case PM_DEP_MOD_GE: equal = (cmp >= 0); break;
@@ -275,11 +275,13 @@ int _alpm_depcmp(pmpkg_t *pkg, pmdepend_t *dep)
if(strlen(dep->version) > 0) {
_alpm_log(PM_LOG_DEBUG, _("depcmp: %s-%s %s %s-%s => %s"),
- pkg->name, pkg->version, mod, dep->name, dep->version,
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
+ mod, dep->name, dep->version,
(equal ? "match" : "no match"));
} else {
_alpm_log(PM_LOG_DEBUG, _("depcmp: %s-%s %s %s => %s"),
- pkg->name, pkg->version, mod, dep->name,
+ alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg),
+ mod, dep->name,
(equal ? "match" : "no match"));
}
}