added support for the package reason field

This commit is contained in:
Aurelien Foret 2005-04-24 20:11:10 +00:00
parent 90b9888d3a
commit 7c04fe95ac
4 changed files with 47 additions and 49 deletions

View file

@ -125,6 +125,11 @@ int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
pm_errno = PM_ERR_PKG_INVALID; pm_errno = PM_ERR_PKG_INVALID;
goto error; goto error;
} }
/* set the reason to EXPLICIT by default
* it will be overwritten in the case of an upgrade or a sync operation */
info->reason = PM_PKG_REASON_EXPLICIT;
/* add the package to the transaction */ /* add the package to the transaction */
trans->packages = pm_list_add(trans->packages, info); trans->packages = pm_list_add(trans->packages, info);
@ -147,10 +152,6 @@ int add_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
/* Check dependencies /* Check dependencies
*/ */
/* ORE ???
No need to check deps if pacman_add was called during a sync:
it is already done in pacman_sync */
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) { if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
PMList *j; PMList *j;
@ -238,7 +239,6 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
TAR *tar = NULL; TAR *tar = NULL;
char expath[PATH_MAX]; char expath[PATH_MAX];
time_t t; time_t t;
pmpkg_t *info = NULL;
PMList *targ, *lp; PMList *targ, *lp;
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
@ -257,26 +257,25 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
}; };
unsigned short pmo_upgrade; unsigned short pmo_upgrade;
char pm_install[PATH_MAX]; char pm_install[PATH_MAX];
pmpkg_t *info = (pmpkg_t *)targ->data;
pmpkg_t *oldpkg = NULL; pmpkg_t *oldpkg = NULL;
info = (pmpkg_t *)targ->data;
errors = 0; errors = 0;
pmo_upgrade = (trans->type == PM_TRANS_TYPE_UPGRADE) ? 1 : 0; pmo_upgrade = (trans->type == PM_TRANS_TYPE_UPGRADE) ? 1 : 0;
/* see if this is an upgrade. if so, remove the old package first */ /* see if this is an upgrade. if so, remove the old package first */
if(pmo_upgrade) { if(pmo_upgrade) {
if(pkg_isin(info, db_get_pkgcache(db))) { pmpkg_t *local = db_get_pkgfromcache(db, info->name);
if(local) {
TRANS_CB(trans, PM_TRANS_EVT_UPGRADE_START, info, NULL); TRANS_CB(trans, PM_TRANS_EVT_UPGRADE_START, info, NULL);
_alpm_log(PM_LOG_FLOW1, "upgrading package %s-%s", info->name, info->version); _alpm_log(PM_LOG_FLOW1, "upgrading package %s-%s", info->name, info->version);
/* we'll need the full record for backup checks later */ /* we'll need to save some record for backup checks later */
oldpkg = pkg_new(); oldpkg = pkg_new();
if(oldpkg) { if(oldpkg) {
STRNCPY(oldpkg->name, info->name, PKG_NAME_LEN); STRNCPY(oldpkg->name, local->name, PKG_NAME_LEN);
STRNCPY(oldpkg->version, info->version, PKG_VERSION_LEN); STRNCPY(oldpkg->version, local->version, PKG_VERSION_LEN);
oldpkg->backup = _alpm_list_strdup(info->backup); oldpkg->backup = _alpm_list_strdup(local->backup);
/* ORE
oldpkg->reason = info->reason;*/
} }
/* pre_upgrade scriptlet */ /* pre_upgrade scriptlet */
@ -297,8 +296,7 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
RET_ERR(PM_ERR_TRANS_ABORT, -1); RET_ERR(PM_ERR_TRANS_ABORT, -1);
} }
/* copy over the install reason */ /* copy over the install reason */
/* ORE? info->reason = local->reason;
info->reason = oldpkg->reason; */
if(remove_loadtarget(tr, db, info->name) == -1) { if(remove_loadtarget(tr, db, info->name) == -1) {
FREETRANS(tr); FREETRANS(tr);
RET_ERR(PM_ERR_TRANS_ABORT, -1); RET_ERR(PM_ERR_TRANS_ABORT, -1);
@ -351,17 +349,6 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
} }
_alpm_log(PM_LOG_FLOW1, "updating database"); _alpm_log(PM_LOG_FLOW1, "updating database");
/* Figure out whether this package was installed explicitly by the user
* or installed as a dependency for another package
*/
info->reason = PM_PKG_REASON_EXPLICIT;
/* ORE
only relevant for sync operations?
usage of info->data should be ok for TRANS_TYPE_ADD, but wrong for
TRANS_TYPE_SYNC
if(pm_list_is_strin(trans->targets, info->data) || pmo_d_resolve) {
info->reason = PM_PKG_REASON_DEPEND;
}*/
/* make an install date (in UTC) */ /* make an install date (in UTC) */
STRNCPY(info->installdate, asctime(gmtime(&t)), sizeof(info->installdate)); STRNCPY(info->installdate, asctime(gmtime(&t)), sizeof(info->installdate));
_alpm_log(PM_LOG_FLOW2, "adding database entry %s", info->name); _alpm_log(PM_LOG_FLOW2, "adding database entry %s", info->name);

View file

@ -69,7 +69,7 @@ int alpm_initialize(char *root)
handle = handle_new(); handle = handle_new();
if(handle == NULL) { if(handle == NULL) {
RET_ERR(PM_ERR_MEM_ERROR, -1); RET_ERR(PM_ERR_MEMORY, -1);
} }
/* lock db */ /* lock db */
@ -111,10 +111,8 @@ int alpm_release()
} }
/* and also sync ones */ /* and also sync ones */
for(i = handle->dbs_sync; i; i = i->next) { for(i = handle->dbs_sync; i; i = i->next) {
if(i->data) { db_close(i->data);
db_close(i->data); i->data = NULL;
i->data = NULL;
}
} }
FREEHANDLE(handle); FREEHANDLE(handle);

View file

@ -254,7 +254,7 @@ int sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, char *n
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
strncpy(targline, name, (PKG_NAME_LEN-1)+1+(DB_TREENAME_LEN-1)+1); STRNCPY(targline, name, (PKG_NAME_LEN-1)+1+(DB_TREENAME_LEN-1)+1);
targ = strchr(targline, '/'); targ = strchr(targline, '/');
if(targ) { if(targ) {
*targ = '\0'; *targ = '\0';
@ -294,7 +294,7 @@ int sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, char *n
/* ORE /* ORE
if(!yesno(":: %s-%s: is up to date. Upgrade anyway? [Y/n] ", lpkgname, lpkgver)) { if(!yesno(":: %s-%s: is up to date. Upgrade anyway? [Y/n] ", lpkgname, lpkgver)) {
}*/ }*/
_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", local->name, local->version);
return(0); return(0);
} }
} }
@ -352,9 +352,6 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
/* pm_errno is set by resolvedeps */ /* pm_errno is set by resolvedeps */
goto error; goto error;
} }
/* ORE
if called from makepkg, reason should be set to REASON_DEPEND
spkg->reason = PM_PKG_REASON_EXPLICIT;*/
} }
for(i = list; i; i = i->next) { for(i = list; i; i = i->next) {
pmpkg_t *spkg = i->data; pmpkg_t *spkg = i->data;
@ -472,7 +469,7 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
{ {
PMList *i; PMList *i;
PMList *data; PMList *data;
pmtrans_t *tr; pmtrans_t *tr = NULL;
int replaces = 0; int replaces = 0;
ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
@ -492,9 +489,15 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
for(i = trans->packages; i; i = i->next) { for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data; pmsyncpkg_t *sync = i->data;
if(sync->type == PM_SYNC_TYPE_REPLACE) { if(sync->type == PM_SYNC_TYPE_REPLACE) {
pmpkg_t *pkg = sync->pkg; PMList *pkgs = sync->data;
if(trans_addtarget(tr, pkg->name)) { PMList *j;
goto error; for(j = pkgs; j; j = j->next) {
pmpkg_t *pkg = j->data;
if(!pkg_isin(pkg, tr->packages)) {
if(trans_addtarget(tr, pkg->name) == -1) {
goto error;
}
}
} }
replaces++; replaces++;
} }
@ -514,7 +517,7 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
goto error; goto error;
} }
} }
trans_free(tr); FREETRANS(tr);
/* install targets */ /* install targets */
_alpm_log(PM_LOG_FLOW1, "installing packages"); _alpm_log(PM_LOG_FLOW1, "installing packages");
@ -531,13 +534,21 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
} }
for(i = trans->packages; i; i = i->next) { for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data; pmsyncpkg_t *sync = i->data;
if(sync->type != PM_SYNC_TYPE_REPLACE) { pmpkg_t *spkg = sync->pkg;
pmpkg_t *spkg = sync->pkg; char str[PATH_MAX];
char str[PATH_MAX]; snprintf(str, PATH_MAX, "%s" PM_CACHEDIR "/%s-%s" PM_EXT_PKG, handle->root, spkg->name, spkg->version);
snprintf(str, PATH_MAX, "%s" PM_CACHEDIR "/%s-%s" PM_EXT_PKG, handle->root, spkg->name, spkg->version); if(trans_addtarget(tr, str) == -1) {
if(trans_addtarget(tr, str) == -1) { goto error;
goto error; }
} /* using list_last() is ok because addtarget() adds the new target at the
* end of the tr->packages list */
spkg = pm_list_last(tr->packages)->data;
if(sync->type == PM_SYNC_TYPE_DEPEND) {
/* ORE
* if called from makepkg, reason should be set to PM_PKG_REASON_DEPEND */
spkg->reason = PM_PKG_REASON_DEPEND;
} else {
spkg->reason = PM_PKG_REASON_EXPLICIT;
} }
} }
if(trans_prepare(tr, &data) == -1) { if(trans_prepare(tr, &data) == -1) {
@ -552,7 +563,7 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
pm_errno = PM_ERR_XXX; pm_errno = PM_ERR_XXX;
goto error; goto error;
} }
trans_free(tr); FREETRANS(tr);
/* propagate replaced packages' requiredby fields to their new owners */ /* propagate replaced packages' requiredby fields to their new owners */
if(replaces) { if(replaces) {
@ -595,6 +606,7 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
return(0); return(0);
error: error:
FREETRANS(tr);
return(-1); return(-1);
} }

View file

@ -133,6 +133,7 @@ int trans_addtarget(pmtrans_t *trans, char *target)
} }
break; break;
} }
trans->targets = pm_list_add(trans->targets, strdup(target)); trans->targets = pm_list_add(trans->targets, strdup(target));
return(0); return(0);