summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/sync.c')
-rw-r--r--lib/libalpm/sync.c71
1 files changed, 28 insertions, 43 deletions
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index ced20c5a..fbe5780d 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -72,13 +72,9 @@ void _alpm_sync_free(pmsyncpkg_t *sync)
/* TODO wow this is ugly */
if(sync->type == PM_SYNC_TYPE_REPLACE) {
- alpm_list_free_inner(sync->data, (alpm_list_fn_free)_alpm_pkg_free);
alpm_list_free(sync->data);
- sync->data = NULL;
- } else {
- _alpm_pkg_free(sync->data);
- sync->data = NULL;
}
+ sync->data = NULL;
FREE(sync);
}
@@ -147,27 +143,21 @@ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local,
* the package to replace.
*/
pmsyncpkg_t *sync;
- pmpkg_t *dummy = _alpm_pkg_dup(lpkg);
- if(dummy == NULL) {
- pm_errno = PM_ERR_MEMORY;
- synclist_free(*syncpkgs);
- return(-1);
- }
+
/* check if spkg->name is already in the packages list. */
sync = _alpm_sync_find(*syncpkgs, alpm_pkg_get_name(spkg));
if(sync) {
/* found it -- just append to the replaces list */
- sync->data = alpm_list_add(sync->data, dummy);
+ sync->data = alpm_list_add(sync->data, lpkg);
} else {
/* none found -- enter pkg into the final sync list */
sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL);
if(sync == NULL) {
- _alpm_pkg_free(dummy);
pm_errno = PM_ERR_MEMORY;
synclist_free(*syncpkgs);
return(-1);
}
- sync->data = alpm_list_add(NULL, dummy);
+ sync->data = alpm_list_add(NULL, lpkg);
*syncpkgs = alpm_list_add(*syncpkgs, sync);
}
_alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (to be replaced by %s-%s)\n",
@@ -251,15 +241,8 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans,
continue;
}
- pmpkg_t *tmp = _alpm_pkg_dup(local);
- if(tmp == NULL) {
- pm_errno = PM_ERR_MEMORY;
- synclist_free(*syncpkgs);
- return(-1);
- }
- sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, tmp);
+ sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, local);
if(sync == NULL) {
- _alpm_pkg_free(tmp);
pm_errno = PM_ERR_MEMORY;
synclist_free(*syncpkgs);
return(-1);
@@ -274,7 +257,7 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans,
int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, char *name)
{
- char targline[PKG_FULLNAME_LEN];
+ char *targline;
char *targ;
alpm_list_t *j;
pmpkg_t *local;
@@ -287,8 +270,8 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ STRDUP(targline, name, RET_ERR(PM_ERR_MEMORY, -1));
- strncpy(targline, name, PKG_FULLNAME_LEN);
targ = strchr(targline, '/');
if(targ) {
/* we are looking for a package in a specific database */
@@ -301,13 +284,15 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
repo_found = 1;
spkg = _alpm_db_get_pkgfromcache(db, targ);
if(spkg == NULL) {
- RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
+ pm_errno = PM_ERR_PKG_NOT_FOUND;
+ goto error;
}
}
}
if(!repo_found) {
_alpm_log(PM_LOG_ERROR, _("repository '%s' not found\n"), targline);
- RET_ERR(PM_ERR_PKG_REPO_NOT_FOUND, -1);
+ pm_errno = PM_ERR_PKG_REPO_NOT_FOUND;
+ goto error;
}
} else {
targ = targline;
@@ -316,7 +301,8 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
spkg = _alpm_db_get_pkgfromcache(db, targ);
}
if(spkg == NULL) {
- RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
+ pm_errno = PM_ERR_PKG_NOT_FOUND;
+ goto error;
}
}
@@ -345,24 +331,24 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
/* add the package to the transaction */
if(!_alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg))) {
- pmpkg_t *dummy = NULL;
- if(local) {
- dummy = _alpm_pkg_dup(local);
- if(dummy == NULL) {
- RET_ERR(PM_ERR_MEMORY, -1);
- }
- }
- sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, dummy);
+ sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, local);
if(sync == NULL) {
- _alpm_pkg_free(dummy);
- RET_ERR(PM_ERR_MEMORY, -1);
+ pm_errno = PM_ERR_MEMORY;
+ goto error;
}
_alpm_log(PM_LOG_DEBUG, "adding target '%s' to the transaction set\n",
alpm_pkg_get_name(spkg));
trans->packages = alpm_list_add(trans->packages, sync);
}
+ FREE(targline);
return(0);
+
+error:
+ if(targline) {
+ FREE(targline);
+ }
+ return(-1);
}
/* Helper functions for alpm_list_remove
@@ -568,17 +554,15 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
conflict->package2, NULL, &doremove);
asked = alpm_list_add(asked, strdup(conflict->package2));
if(doremove) {
- pmpkg_t *q = _alpm_pkg_dup(local);
if(sync->type != PM_SYNC_TYPE_REPLACE) {
/* switch this sync type to REPLACE */
sync->type = PM_SYNC_TYPE_REPLACE;
- _alpm_pkg_free(sync->data);
sync->data = NULL;
}
/* append to the replaces list */
_alpm_log(PM_LOG_DEBUG, "electing '%s' for removal\n",
conflict->package2);
- sync->data = alpm_list_add(sync->data, q);
+ sync->data = alpm_list_add(sync->data, local);
/* see if the package is in the current target list */
pmsyncpkg_t *rsync = _alpm_sync_find(trans->packages,
conflict->package2);
@@ -618,7 +602,8 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
}
}
FREELIST(asked);
- FREELIST(deps);
+ alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free);
+ alpm_list_free(deps);
ret = -1;
goto cleanup;
}
@@ -776,7 +761,7 @@ static int apply_deltas(pmtrans_t *trans, alpm_list_t *patches)
pmpkg_t *pkg;
pmdelta_t *d;
char command[PATH_MAX], fname[PATH_MAX];
- char pkgfilename[PKG_FILENAME_LEN];
+ char pkgfilename[PATH_MAX];
pkg = alpm_list_getdata(p);
p = alpm_list_next(p);
@@ -811,7 +796,7 @@ static int apply_deltas(pmtrans_t *trans, alpm_list_t *patches)
_alpm_log(PM_LOG_DEBUG, _("command: %s\n"), command);
- snprintf(pkgfilename, PKG_FILENAME_LEN, "%s-%s-%s" PKGEXT,
+ snprintf(pkgfilename, PATH_MAX, "%s-%s-%s" PKGEXT,
pkg->name, d->to, pkg->arch);
EVENT(trans, PM_TRANS_EVT_DELTA_PATCH_START, pkgfilename, d->filename);