From 649878d5d48fc66431cea7402187787c9489c814 Mon Sep 17 00:00:00 2001 From: jg Date: Tue, 4 Feb 2025 21:35:01 +0100 Subject: [PATCH] feat: flag added, missing abort transaction if flag set --- lib/libalpm/alpm.h | 3 ++- lib/libalpm/remove.c | 1 + src/pacman/pacman.c | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index abdea798..0ad8db9d 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -2816,7 +2816,8 @@ typedef enum _alpm_transflag_t { ALPM_TRANS_FLAG_NOSCRIPTLET = (1 << 10), /** Ignore dependency conflicts. */ ALPM_TRANS_FLAG_NOCONFLICTS = (1 << 11), - /* (1 << 12) flag can go here */ + /** Cancel removal of package if it's optdepends of another package. */ + ALPM_TRANS_KEEP_OPTIONALS = (1 << 12), /** Do not install a package if it is already installed and up to date. */ ALPM_TRANS_FLAG_NEEDED = (1 << 13), /** Use ALPM_PKG_REASON_EXPLICIT when installing packages. */ diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index e7634994..2da10fe6 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -257,6 +257,7 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) /* Note packages being removed that are optdepends for installed packages */ if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { + /*DEV_COMMENT: This is where the check is done, use this logic to check flag ALPM_TRANS_KEEP_OPTIONALS and abort transaction if flag set */ remove_notify_needed_optdepends(handle, trans->remove); } diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 8f5fb6de..7952f597 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -729,6 +729,11 @@ static int parsearg_remove(int opt) case 'u': config->flags |= ALPM_TRANS_FLAG_UNNEEDED; break; + case 'k': + if (config->flags & ALPM_TRANS_FLAG_RECURSE || config->flags & ALPM_TRANS_FLAG_RECURSEALL) { + config->flags |= ALPM_TRANS_KEEP_OPTIONALS; + } + break; default: return 1; }