Hi,
From what I could see, the function trans_init that comes right before the prompt has already specific messages for each operation, so I consider that this new implementation fits the purpose. My motivation to submit this patch is that it's pretty common for AUR-helpers to automatically invoke pacman after a build, but correct transaction error handling is quite rare. So I thought that to implement a handling mechanism in the user side would solve the problem not only in that case, but also for other scripts that invoke pacman.
This description makes me doubt as to whether this is something that pacman needs, but rather something that these AUR-helpers may want? I also wonder if it'd be friendlier to notify the user the *reason* why the transaction failed, so they can better decide whether to try again or not. Cheers! -Santiago
Signed-off-by: Pedro <pedrocga1@gmail.com> --- src/pacman/remove.c | 13 ++++++++++--- src/pacman/sync.c | 13 ++++++++++--- src/pacman/upgrade.c | 13 ++++++++++--- 3 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 9920f502..66bb100d 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -87,9 +87,16 @@ int pacman_remove(alpm_list_t *targets) }
/* Step 0: create a new transaction */ - if(trans_init(config->flags, 0) == -1) { - return 1; - } + while(1) { + if(trans_init(config->flags, 1) == -1) { + if(config->noconfirm || yesno(_("Retry the operation with the same flags?")) == 0) { + return 1; + } + /* Try again */ + continue; + } + break; + }
/* Step 1: add targets to the created transaction */ for(i = targets; i; i = alpm_list_next(i)) { diff --git a/src/pacman/sync.c b/src/pacman/sync.c index f7dcb958..e472d89a 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -694,9 +694,16 @@ static int sync_trans(alpm_list_t *targets) alpm_list_t *i;
/* Step 1: create a new transaction... */ - if(trans_init(config->flags, 1) == -1) { - return 1; - } + while(1) { + if(trans_init(config->flags, 1) == -1) { + if(config->noconfirm == 1 || yesno(_("Retry the operation with the same flags?")) == 0) { + return 1; + } + /* Try again */ + continue; + } + break; + }
/* process targets */ for(i = targets; i; i = alpm_list_next(i)) { diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c index 5f984e44..2ea74618 100644 --- a/src/pacman/upgrade.c +++ b/src/pacman/upgrade.c @@ -79,9 +79,16 @@ int pacman_upgrade(alpm_list_t *targets) }
/* Step 1: create a new transaction */ - if(trans_init(config->flags, 1) == -1) { - retval = 1; - goto fail_free; + while(1) { + if(trans_init(config->flags, 1) == -1) { + if(config-->noconfirm || yesno(_("Retry the operation with the same flags?")) == 0) { + retval = 1; + goto fail_free; + } + /* Try again */ + continue; + } + break; }
printf(_("loading packages...\n")); -- 2.26.2