- fixed a compilation warning

- added missing alpm_trans_release() calls upon transation completion
- put back error messages from pacman 2.x in case of PM_ERR_HANDLE_LOCK error
This commit is contained in:
Aurelien Foret 2006-01-26 20:46:48 +00:00
parent 7818e6f745
commit fb2331ab8b
3 changed files with 52 additions and 24 deletions

View File

@ -38,6 +38,7 @@ int pacman_add(list_t *targets)
{
PM_LIST *data;
list_t *i;
int retval = 0;
if(targets == NULL) {
return(0);
@ -62,6 +63,10 @@ int pacman_add(list_t *targets)
if(alpm_trans_init((config->upgrade == 0) ? PM_TRANS_TYPE_ADD : PM_TRANS_TYPE_UPGRADE,
config->flags, cb_trans_evt, cb_trans_conv) == -1) {
ERR(NL, "%s\n", alpm_strerror(pm_errno));
if(pm_errno == PM_ERR_HANDLE_LOCK) {
MSG(NL, " if you're sure a package manager is not already running,\n"
" you can remove %s\n", PM_LOCK);
}
return(1);
}
@ -70,7 +75,8 @@ int pacman_add(list_t *targets)
for(i = targets; i; i = i->next) {
if(alpm_trans_addtarget(i->data) == -1) {
ERR(NL, "failed to add target '%s' (%s)\n", (char *)i->data, alpm_strerror(pm_errno));
goto error;
retval = 1;
goto cleanup;
}
}
MSG(CL, "done.");
@ -116,23 +122,26 @@ int pacman_add(list_t *targets)
default:
break;
}
goto error;
retval = 1;
goto cleanup;
}
/* Step 3: actually perform the installation
*/
if(alpm_trans_commit(NULL) == -1) {
ERR(NL, "failed to commit transaction (%s)\n", alpm_strerror(pm_errno));
goto error;
retval = 1;
goto cleanup;
}
return(0);
error:
/* Step 4: release transaction resources
*/
cleanup:
if(alpm_trans_release() == -1) {
ERR(NL, "failed to release transaction (%s)\n", alpm_strerror(pm_errno));
}
return(1);
return(retval);
}
/* vim: set ts=2 sw=2 noet: */

View File

@ -41,6 +41,7 @@ int pacman_remove(list_t *targets)
PM_LIST *data;
list_t *i;
list_t *finaltargs = NULL;
int retval = 0;
if(targets == NULL) {
return(0);
@ -77,13 +78,19 @@ int pacman_remove(list_t *targets)
*/
if(alpm_trans_init(PM_TRANS_TYPE_REMOVE, config->flags, cb_trans_evt, cb_trans_conv) == -1) {
ERR(NL, "failed to init transaction (%s)\n", alpm_strerror(pm_errno));
goto error;
if(pm_errno == PM_ERR_HANDLE_LOCK) {
MSG(NL, " if you're sure a package manager is not already running,\n"
" you can remove %s\n", PM_LOCK);
}
FREELIST(finaltargs);
return(1);
}
/* and add targets to it */
for(i = finaltargs; i; i = i->next) {
if(alpm_trans_addtarget(i->data) == -1) {
ERR(NL, "failed to add target '%s' (%s)\n", (char *)i->data, alpm_strerror(pm_errno));
goto error;
retval = 1;
goto cleanup;
}
}
@ -104,7 +111,8 @@ int pacman_remove(list_t *targets)
default:
break;
}
goto error;
retval = 1;
goto cleanup;
}
/* Warn user in case of dangerous operation
@ -121,7 +129,8 @@ int pacman_remove(list_t *targets)
FREELIST(i);
/* get confirmation */
if(yesno("\nDo you want to remove these packages? [Y/n] ") == 0) {
goto error;
retval = 1;
goto cleanup;
}
MSG(NL, "\n");
}
@ -130,21 +139,20 @@ int pacman_remove(list_t *targets)
*/
if(alpm_trans_commit(NULL) == -1) {
ERR(NL, "failed to commit transaction (%s)\n", alpm_strerror(pm_errno));
goto error;
retval = 1;
goto cleanup;
}
/* Step 4: cleanup */
/* Step 4: release transaction resources
*/
cleanup:
FREELIST(finaltargs);
return(0);
error:
FREELIST(finaltargs);
if(alpm_trans_release() == -1) {
ERR(NL, "failed to release transaction (%s)\n", alpm_strerror(pm_errno));
}
return(1);
return(retval);
}
/* vim: set ts=2 sw=2 noet: */

View File

@ -414,8 +414,11 @@ int pacman_sync(list_t *targets)
*/
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv) == -1) {
ERR(NL, "failed to init transaction (%s)\n", alpm_strerror(pm_errno));
retval = 1;
goto cleanup;
if(pm_errno == PM_ERR_HANDLE_LOCK) {
MSG(NL, " if you're sure a package manager is not already running,\n"
" you can remove %s\n", PM_LOCK);
}
return(1);
}
if(config->op_s_upgrade) {
@ -450,8 +453,11 @@ int pacman_sync(list_t *targets)
}
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv) == -1) {
ERR(NL, "failed to init transaction (%s)\n", alpm_strerror(pm_errno));
retval = 1;
goto cleanup;
if(pm_errno == PM_ERR_HANDLE_LOCK) {
MSG(NL, " if you're sure a package manager is not already running,\n"
" you can remove %s\n", PM_LOCK);
}
return(1);
}
if(alpm_trans_addtarget("pacman") == -1) {
ERR(NL, "could not add target '%s': %s\n", (char *)i->data, alpm_strerror(pm_errno));
@ -524,7 +530,7 @@ int pacman_sync(list_t *targets)
for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) {
PM_DEPMISS *miss = alpm_list_getdata(lp);
MSG(NL, ":: %s: %s %s", alpm_dep_getinfo(miss, PM_DEP_TARGET),
alpm_dep_getinfo(miss, PM_DEP_TYPE) == PM_DEP_TYPE_DEPEND ? "requires" : "is required by",
(int)alpm_dep_getinfo(miss, PM_DEP_TYPE) == PM_DEP_TYPE_DEPEND ? "requires" : "is required by",
alpm_dep_getinfo(miss, PM_DEP_NAME));
switch((int)alpm_dep_getinfo(miss, PM_DEP_MOD)) {
case PM_DEP_MOD_EQ: MSG(CL, "=%s", alpm_dep_getinfo(miss, PM_DEP_VERSION)); break;
@ -779,8 +785,13 @@ int pacman_sync(list_t *targets)
}
}
/* Step 4: release transaction resources
*/
cleanup:
alpm_trans_release();
if(alpm_trans_release() == -1) {
ERR(NL, "failed to release transaction (%s)\n", alpm_strerror(pm_errno));
}
return(retval);
}