sync.c : duplicate the target before modifying it

It was probably a bad idea to modify the target directly in case of
repo/pkg syntax.

Duplicating it also allows us to keep the original target string, which
is more informative when printing errors.

Also remove a duplicated error message from libalpm, and improve the
message already returned to the frontend.

$ pacman -S foo/bar

before
error: repository 'foo' not found
error: 'bar': no such repository

after
error: 'foo/bar': could not find repository for target

Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Xavier Chantry 2009-09-15 16:07:25 +02:00 committed by Dan McGee
parent 95cb4b6874
commit f4809dcc9c
3 changed files with 19 additions and 18 deletions

View File

@ -120,7 +120,7 @@ const char SYMEXPORT *alpm_strerror(int err)
case PM_ERR_PKG_INVALID_ARCH:
return _("package architecture is not valid");
case PM_ERR_PKG_REPO_NOT_FOUND:
return _("no such repository");
return _("could not find repository for target");
/* Deltas */
case PM_ERR_DLT_INVALID:
return _("invalid or corrupted delta");

View File

@ -323,7 +323,6 @@ int SYMEXPORT alpm_sync_dbtarget(char *dbname, char *target)
}
}
if(dbs == NULL) {
_alpm_log(PM_LOG_ERROR, _("repository '%s' not found\n"), dbname);
RET_ERR(PM_ERR_PKG_REPO_NOT_FOUND, -1);
}
return(_alpm_sync_target(dbs, target));

View File

@ -551,32 +551,34 @@ static alpm_list_t *syncfirst() {
static int process_target(char *target)
{
/* process targets */
char *targ = strchr(target, '/');
char *db = NULL;
int ret;
if(targ) {
*targ = '\0';
targ++;
db = target;
ret = alpm_sync_dbtarget(db,targ);
char *targstring = strdup(target);
char *targname = strchr(targstring, '/');
char *dbname = NULL;
int ret = 0;
if(targname) {
*targname = '\0';
targname++;
dbname = targstring;
ret = alpm_sync_dbtarget(dbname,targname);
} else {
targ = target;
ret = alpm_sync_target(targ);
targname = targstring;
ret = alpm_sync_target(targname);
}
if(ret == -1) {
if(pm_errno == PM_ERR_TRANS_DUP_TARGET
|| pm_errno == PM_ERR_PKG_IGNORED) {
/* just skip duplicate or ignored targets */
pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targ);
return(0);
pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), target);
} else {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", target,
alpm_strerrorlast());
ret = 1;
}
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
targ, alpm_strerrorlast());
return(1);
}
return(0);
free(targstring);
return(ret);
}
static int sync_trans(alpm_list_t *targets)