diff --git a/src/main.cpp b/src/main.cpp index c02f69b..65a1451 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include #pragma GCC diagnostic ignored "-Wvla" #include "args.hpp" @@ -144,7 +145,8 @@ int installPkg(alpm_list_t *pkgNames) { bool useGit = config->useGit; path cacheDir = config->cacheDir; - bool returnStatus = true, stat; + bool returnStatus = true; + bool stat; vector pacmanPkgs; // list of pacman packages to install, to avoid spamming pacman. vector pkgNamesVec; @@ -184,101 +186,69 @@ int installPkg(alpm_list_t *pkgNames) { // this feels horrible despite being 100% correct and probably not problematic. // it just feels like we should ask for every package. + // Toni500 note: do someone agree with this above? because I don't vector AURPkgs = filterAURPkgsNames(pkgNamesVec, alpm_get_syncdbs(config->handle), true); + for (const auto& pkg : pkgNamesVec) { + // Check if pkg is not in aurPkgNamesSet + if (std::find(AURPkgs.begin(), AURPkgs.end(), pkg) == AURPkgs.end()) { + pacmanPkgs.push_back(pkg.data()); + } + } + if (!op.op_s_cleanbuild && !AURPkgs.empty()) pkgsToCleanBuild = askUserForList(AURPkgs, PROMPT_LIST_CLEANBUILDS); if (!config->noconfirm && !AURPkgs.empty()) pkgsToReview = askUserForList(AURPkgs, PROMPT_LIST_REVIEWS); - - for (size_t i = 0; i < pkgNamesVec.size(); i++) { - vector pkgs = backend->search(pkgNamesVec[i], useGit, config->aurOnly, true); + for (auto& pkg_name : AURPkgs) { - optional> oSelectedPkg = askUserForPkg(pkgs, *backend, useGit); + path pkgDir = path(cacheDir) / pkg_name; - if (!oSelectedPkg) { + stat = useGit ? backend->download_git(AUR_URL_GIT(pkg_name), pkgDir) : backend->download_tar(AUR_URL_TAR(pkg_name), pkgDir); + if (!stat) { + log_println(ERROR, _("Failed to download {}"), pkg_name); returnStatus = false; continue; } - vector selectedPkg = oSelectedPkg.value(); - - for (size_t i = 0; i < selectedPkg.size(); i++) { - TaurPkg_t pkg = selectedPkg[i]; - - if (pkg.db_name != "aur") { - pacmanPkgs.push_back(pkg.name); - continue; - } - - path pkgDir = path(cacheDir) / pkg.name; - bool cleanBuild = op.op_s_cleanbuild ? false : std::find(pkgsToCleanBuild.begin(), pkgsToCleanBuild.end(), pkg.name) != pkgsToCleanBuild.end(); - bool review = config->noconfirm ? false : std::find(pkgsToReview.begin(), pkgsToReview.end(), pkg.name) != pkgsToReview.end(); - - if (cleanBuild) { - log_println(INFO, _("Removing {}"), pkgDir.c_str()); - std::filesystem::remove_all(pkgDir); - } - - stat = useGit ? backend->download_git(AUR_URL_GIT(pkg.name), pkgDir) : backend->download_tar(AUR_URL_TAR(pkg.name), pkgDir); - if (!stat) { - log_println(ERROR, _("Failed to download {}"), pkg.name); - returnStatus = false; - continue; - } - - if (review || askUserYorN(YES, PROMPT_YN_EDIT_PKGBUILD, pkg.name)) { - // cmd is just a workaround for making possible - // that editor can have flags, e.g nano --modernbindings - // instead of creating another config variable - // This is really ugly - // because u can't convert std::vector to std::vector - vector _cmd; - vector cmd; - for (auto& str : config->editor) - _cmd.push_back(str); - _cmd.push_back((pkgDir / "PKGBUILD").string()); - - for (auto& str : _cmd) - cmd.push_back(str.c_str()); - - taur_exec(cmd); - - if (!askUserYorN(YES, PROMPT_YN_PROCEED_INSTALL)) - return false; - } - - stat = backend->handle_aur_depends(pkg, cacheDir, backend->get_all_local_pkgs(true), useGit); - - if (!stat) { - log_println(ERROR, _("Installing AUR dependencies for your package has failed.")); - returnStatus = false; - continue; - } - - stat = backend->build_pkg(pkg.name, pkgDir, false); - - if (!stat) { - log_println(ERROR, _("Building your package has failed.")); - returnStatus = false; - continue; - } + } - pkgs_to_install += built_pkg + ' '; + for (string_view& pkg : pkgsToCleanBuild) { + path pkgDir = path(cacheDir) / pkg; + if (!useGit) { + log_println(INFO, _("Removing {}"), pkgDir.c_str()); + std::filesystem::remove_all(pkgDir); + } + else { + log_println(INFO, _("Cleaning {}"), pkgDir.c_str()); + taur_exec({config->git.c_str(), "-C", pkgDir.c_str(), "clean", "-xffd"}); } } - if (!pkgs_to_install.empty()) { - 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; - } + // cmd is just a workaround for making possible + // that editor can have flags, e.g nano --modernbindings + // instead of creating another config variable + // This is really ugly + // because you can't convert std::vector to std::vector + for (string_view& pkg : pkgsToReview) { + path pkgDir = path(cacheDir) / pkg; + vector _cmd; + vector cmd; + for (auto& str : config->editor) + _cmd.push_back(str); + _cmd.push_back((pkgDir / "PKGBUILD").string()); + + for (auto& str : _cmd) + cmd.push_back(str.c_str()); + + taur_exec(cmd); } - + + if (!pkgsToReview.empty() && !askUserYorN(YES, PROMPT_YN_PROCEED_INSTALL)) + return false; + if (!config->aurOnly && (op.op_s_upgrade || !pacmanPkgs.empty())) { if (op.op_s_upgrade) log_println(INFO, _("Upgrading system packages!")); @@ -301,6 +271,57 @@ int installPkg(alpm_list_t *pkgNames) { backend->update_all_aur_pkgs(cacheDir, useGit); } + for (size_t i = 0; i < AURPkgs.size(); i++) { + vector pkgs = backend->search(AURPkgs[i], useGit, config->aurOnly, true); + + optional> oSelectedPkg = askUserForPkg(pkgs, *backend, useGit); + + if (!oSelectedPkg) { + returnStatus = false; + continue; + } + + vector selectedPkg = oSelectedPkg.value(); + + TaurPkg_t pkg = selectedPkg[0]; + + path pkgDir = path(cacheDir) / pkg.name; + + stat = backend->handle_aur_depends(pkg, cacheDir, backend->get_all_local_pkgs(true), useGit); + + if (!stat) { + log_println(ERROR, _("Installing AUR dependencies for your package has failed.")); + returnStatus = false; + continue; + } + + stat = backend->build_pkg(pkg.name, pkgDir, false); + + if (!stat) { + log_println(ERROR, _("Building {} has failed."), pkg.name); + returnStatus = false; + pkgs_failed_to_build += pkg.name + ' '; + log_println(DEBUG, "pkgs_failed_to_build = {}", pkgs_failed_to_build); + continue; + } + + pkgs_to_install += built_pkg + ' '; + } + + if (!pkgs_to_install.empty()) { + 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 (!pkgs_failed_to_build.empty()) { + pkgs_failed_to_build.erase(pkgs_failed_to_build.end() - 1); + log_println(WARN, fg(color.red), _("Failed to upgrade: {}"), pkgs_failed_to_build); + log_println(INFO, fg(color.cyan), _("Tip: try to run taur with \"-S {}\" (e.g \"taur -S {}\")"), pkgs_failed_to_build, pkgs_failed_to_build); + } return returnStatus; } diff --git a/src/taur.cpp b/src/taur.cpp index a88a508..4b55369 100644 --- a/src/taur.cpp +++ b/src/taur.cpp @@ -9,7 +9,7 @@ TaurBackend::TaurBackend(Config& cfg) : config(cfg) {} bool TaurBackend::download_git(string_view url, path out_path) { if (std::filesystem::exists(path(out_path) / ".git")) { - return taur_exec({config.git.c_str(), "-C", out_path.c_str(), "pull", "--rebase", "--autostash", "--ff-only"}); + return taur_exec({config.git.c_str(), "-C", out_path.c_str(), "pull", "--autostash", "--rebase", "--ff-only", "--force"}); } else { if (std::filesystem::exists(path(out_path))) std::filesystem::remove_all(out_path); @@ -238,7 +238,7 @@ bool TaurBackend::build_pkg(string_view pkg_name, string extracted_path, bool al if (!alreadyprepared) { log_println(INFO, _("Verifying package sources..")); - makepkg_exec({"--verifysource", "--skippgpcheck", "-f", "-Cc"}); + makepkg_exec({"--verifysource", "--skippgpcheck", "-fs", "-Cc"}); log_println(INFO, _("Preparing for compilation..")); makepkg_exec({"--nobuild", "--skippgpcheck", "-fs", "-C", "--ignorearch"}); @@ -615,11 +615,11 @@ vector TaurBackend::search(string_view query, bool useGit, bool aurOn if (!aurOnly) pacPkgs = this->search_pac(query); - size_t count = aurPkgs.size() + pacPkgs.size(); + size_t allPkgsSize = aurPkgs.size() + pacPkgs.size(); vector combined; - combined.reserve(count); + combined.reserve(allPkgsSize); if (!aurPkgs.empty()) combined.insert(combined.end(), aurPkgs.begin(), aurPkgs.end());