From 2b7af194d7fa328bc05f0c024a76d89e92051c22 Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Sun, 9 Feb 2025 12:32:58 +0100 Subject: [PATCH] feat: added --help description, added check for flag used without -s or --recursive and show warning --- lib/libalpm/remove.c | 10 +++++++++- src/pacman/conf.h | 1 + src/pacman/pacman.c | 8 +++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index dd9b7d58..75e9d861 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -267,10 +267,18 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data) removing_optdepends = remove_notify_needed_optdepends(handle, trans->remove); } - if (trans->flags & ALPM_TRANS_FLAG_KEEPOPTIONALS && removing_optdepends == 1) { + /* -Rks or Rsk == -Rs then -Rk */ + if (trans->flags & ALPM_TRANS_FLAG_RECURSE + && trans->flags & ALPM_TRANS_FLAG_KEEPOPTIONALS + && removing_optdepends == 1) { RET_ERR(handle, ALPM_ERR_REMOVING_OPTDEPENDS_DEPS, -1); } + if (!(trans->flags & ALPM_TRANS_FLAG_RECURSE) + && trans->flags & ALPM_TRANS_FLAG_KEEPOPTIONALS) { + _alpm_log(handle, ALPM_LOG_WARNING, _("-k is set without -s or --recursive, ignoring flag...\n")); + } + if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) { event.type = ALPM_EVENT_CHECKDEPS_DONE; EVENT(handle, &event); diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 5bffd187..c2975848 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -209,6 +209,7 @@ enum { OP_UPGRADES, OP_SYSUPGRADE, OP_UNNEEDED, + OP_KEEPOPTDEP, OP_VERBOSE, OP_DOWNLOADONLY, OP_REFRESH, diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 6105ab8e..4ac9e015 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -126,6 +126,8 @@ static void usage(int op, const char * const myname) addlist(_(" -n, --nosave remove configuration files\n")); addlist(_(" -s, --recursive remove unnecessary dependencies\n" " (-ss includes explicitly installed dependencies)\n")); + addlist(_(" -k, --keepoptdep keep the packages flagged as optdepends by other packages\n" + " (only applied when using -s or --recursive)\n")); addlist(_(" -u, --unneeded remove unneeded packages\n")); } else if(op == PM_OP_UPGRADE) { printf("%s: %s {-U --upgrade} [%s] <%s>\n", str_usg, myname, str_opt, str_file); @@ -729,10 +731,9 @@ static int parsearg_remove(int opt) case 'u': config->flags |= ALPM_TRANS_FLAG_UNNEEDED; break; + case OP_KEEPOPTDEP: case 'k': - if (config->flags & ALPM_TRANS_FLAG_RECURSE || config->flags & ALPM_TRANS_FLAG_RECURSEALL) { - config->flags |= ALPM_TRANS_FLAG_KEEPOPTIONALS; - } + config->flags |= ALPM_TRANS_FLAG_KEEPOPTIONALS; break; default: return 1; @@ -959,6 +960,7 @@ static int parseargs(int argc, char *argv[]) {"upgrades", no_argument, 0, OP_UPGRADES}, {"sysupgrade", no_argument, 0, OP_SYSUPGRADE}, {"unneeded", no_argument, 0, OP_UNNEEDED}, + {"keepoptdep", no_argument, 0, OP_KEEPOPTDEP}, {"verbose", no_argument, 0, OP_VERBOSE}, {"downloadonly", no_argument, 0, OP_DOWNLOADONLY}, {"refresh", no_argument, 0, OP_REFRESH},