From 5621922a4fee39864eebba4d95bd9a1282b2f0e5 Mon Sep 17 00:00:00 2001 From: Toni500git Date: Tue, 30 Apr 2024 18:49:07 +0200 Subject: [PATCH] Few things * add more infos for the user * print only AUR packages when asked which to review/cleanbuild * added multi-install for both system and AUR pkgs (1st AUR ones, then system) --- include/util.hpp | 11 +++++++---- src/main.cpp | 23 +++++++++++++---------- src/util.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/include/util.hpp b/include/util.hpp index 18feea9..3ec8821 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -74,6 +74,7 @@ string makepkg_list(string const& pkg_name, string con void free_list_and_internals(alpm_list_t *list); fmt::text_style getColorFromDBName(string_view db_name); vector filterAURPkgs(vector pkgs, alpm_list_t *syncdbs, bool inverse); +vector filterAURPkgsNames(vector pkgs, alpm_list_t *syncdbs, bool inverse); string shell_exec(string_view cmd); vector split(string_view text, char delim); fmt::rgb hexStringToColor(string_view hexstr); @@ -261,12 +262,14 @@ bool askUserYorN(bool def, prompt_yn pr, Args&&... args) { */ template >> vector askUserForList(vector &list, prompt_list pr, bool required = false) { - string sep_str = "Type the index of each package (e.g 4 12 2)"; + string sep_str = "Type the index of each package (eg: \"0 1 2\", \"0-2\", \"*\" for all, \"n\" for none)"; string result_str; for (size_t i = 0; i < list.size(); i++) fmt::println(fmt::fg(color.index), "[{}] {}", i, fmt::format(BOLD | fmt::fg(fmt::color::white), "{}", list[i])); - + + log_println(INFO, "{}", sep_str); + switch (pr) { case PROMPT_LIST_CLEANBUILDS: log_printf(INFO, BOLD, "Packages to completely rebuild: "); @@ -290,7 +293,7 @@ vector askUserForList(vector &list, prompt_list pr, bool required = false) while (std::getline(std::cin, result_str)) { - if (result_str.empty() && !required) { + if ((result_str.empty() && !required) || result_str == "n") { std::cout << std::endl; return {}; } @@ -304,7 +307,7 @@ vector askUserForList(vector &list, prompt_list pr, bool required = false) bool breakandcontinue = false; for (size_t i = 0; i < input_indices.size() && !breakandcontinue; i++) { // 1-5 means 1 through 5 - if (input_indices[i].find('-') != std::string::npos) { + if (input_indices[i].find('-') != string::npos) { vector loop_bounds = split(input_indices[i], '-'); if (loop_bounds.size() != 2 || !is_numerical(loop_bounds[0]) || !is_numerical(loop_bounds[1])) { log_printf(WARN, "Invalid loop range! (loop ranges look like \"0-5\"): "); diff --git a/src/main.cpp b/src/main.cpp index 79a42be..318acbb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -133,7 +133,7 @@ int installPkg(alpm_list_t *pkgNames) { bool returnStatus = true; vector pacmanPkgs; // list of pacman packages to install, to avoid spamming pacman. - vector pkgNamesVec; + vector pkgNamesVec, aurPkgNamesVec; if (op.op_s_upgrade) { if (!config->aurOnly) { @@ -156,15 +156,17 @@ int installPkg(alpm_list_t *pkgNames) { if (pkgNamesVec.empty()) return false; + aurPkgNamesVec = filterAURPkgsNames(pkgNamesVec, alpm_get_syncdbs(config->handle), true); + vector pkgNamesToCleanBuild, pkgNamesToReview; if (!op.op_s_search) { if (!op.op_s_cleanbuild) - pkgNamesToCleanBuild = askUserForList(pkgNamesVec, PROMPT_LIST_CLEANBUILDS); + pkgNamesToCleanBuild = askUserForList(aurPkgNamesVec, PROMPT_LIST_CLEANBUILDS); else pkgNamesToCleanBuild = {}; - pkgNamesToReview = askUserForList(pkgNamesVec, PROMPT_LIST_REVIEWS); + pkgNamesToReview = askUserForList(aurPkgNamesVec, PROMPT_LIST_REVIEWS); } for (size_t i = 0; i < pkgNamesVec.size(); i++) { @@ -262,15 +264,16 @@ int installPkg(alpm_list_t *pkgNames) { returnStatus = false; continue; } - - log_println(DEBUG, "Installing {}.", pkg.name); - if (!pacman_exec("-U", split(built_pkg, ' '), false)) { - log_println(ERROR, "Failed to install {}.", pkg.name); - returnStatus = false; - continue; - } + pkgs_to_install += built_pkg + ' '; } } + + log_println(DEBUG, "Installing {}", fmt::join(pkgNamesVec, " ")); + pkgs_to_install.erase(pkgs_to_install.length()-1); + if (!pacman_exec("-U", split(pkgs_to_install, ' '), false)) { + log_println(ERROR, "Failed to install {}.", fmt::join(pkgNamesVec, " ")); + returnStatus = false; + } if (!pacmanPkgs.empty()) { string op_s = "-S"; diff --git a/src/util.cpp b/src/util.cpp index c77fc78..1e2ae54 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -274,6 +274,7 @@ bool makepkg_exec(string_view cmd, bool exitOnFailure) { if (config->noconfirm) ccmd.push_back("--noconfirm"); + if (!config->colors) ccmd.push_back("--nocolor"); @@ -491,6 +492,31 @@ vector filterAURPkgs(vector pkgs, alpm_list_t *syncd return out; } +/** Filters out/only AUR packages (names only). + * Default behavior is filtering out. + * @param pkgs a unique_ptr to a list of packages to filter. + * @param inverse a bool that, if true, will return only AUR packages instead of the other way around. + * @return an optional unique_ptr to a result. +*/ +vector filterAURPkgsNames(vector pkgs, alpm_list_t *syncdbs, bool inverse) { + vector out; + + for (; syncdbs; syncdbs = syncdbs->next) { + for (size_t i = 0; i < pkgs.size(); i++) { + bool existsInSync = alpm_db_get_pkg((alpm_db_t *)(syncdbs->data), pkgs[i].data()) != nullptr; + + if ((existsInSync && inverse) || (!existsInSync && !inverse)) + pkgs[i] = ""; + } + } + + for (size_t i = 0; i < pkgs.size(); i++) + if (pkgs[i].length()) + out.push_back(pkgs[i]); + + return out; +} + string getTitleFromVotes(float votes) { if (votes < 2) return "Untrustable";